Giter Site home page Giter Site logo

anymap's People

Contributors

chris-morgan avatar drbawb avatar hellow554 avatar reem avatar tivek avatar tomassedovic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anymap's Issues

How to actually use this

I want to crate a Map<Component>, but whatever I do, Rust always says error[E0277]: the trait bound `Component + 'static: anymap::any::UncheckedAnyExt` is not satisfied.

I have tried so much now:

pub trait Component {
pub trait Component: std::any::Any {
pub trait Component: anymap::any::Any {
pub trait Component: anymap::any::Any + anymap::any::UncheckedAnyExt {
pub trait Component: 'static + anymap::any::Any + anymap::any::UncheckedAnyExt {
pub trait Component: 'static + std::any::Any + anymap::any::Any + anymap::any::UncheckedAnyExt {

I am lost on what to do...

concurrent feature

Just for the record, since we already discussed this a bit.

It would be nice if we created a concurrent feature that would basically add the Sync + Send bounds where necessary. I already do something similar in my minor fork and found that it's a very straightforward change compared to making it clonable.

Personally I really need this so that I could put stuff in an Arc and send it to a thread pool, but I understand if it's more of a hassle than it's worth here.

Specifically I need it to be both clonable and concurrent. What I was discussing on IRC was that I don't know if it'd be possible to have to independent yet composable features for each thing: clone and concurrent, given the fact (?) that the with_clone stuff would need to have the Sync + Send bounds added.

Recent change in core::any::TypeId breaks the `type_id_hasher` unittest

Howdy,

The size of TypeId changed in rust-lang/rust@9e5573a, and the unittest type_id_hasher no longer builds:

cannot transmute between types of different sizes, or dependently-sized types
    |
638 |         assert_eq!(hasher.finish(), unsafe { core::mem::transmute::<TypeId, u64>(type_id) });
    |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: source type: `TypeId` (128 bits)
    = note: target type: `u64` (64 bits)

It seems to me that the commit doesn't affect the behavior of the anymap crate, it only affects the unittest. Could you please confirm that that is the case?

Any way to create a singleton of this?

for example lazy_static? or using ONCE?

Best I could do is

pub fn model_store() -> Arc<Mutex<AnyMap>> {
    static mut STORE: *const Arc<Mutex<anymap::AnyMap>> = 0 as *const Arc<Mutex<anymap::AnyMap>>;
    static ONCE: Once = Once::new();
    ONCE.call_once(|| {
        let singleton = AnyMap::new();
        unsafe { STORE = std::mem::transmute(Arc::new(Mutex::new(singleton)))};
    });
    unsafe { (*STORE).clone() } // Is this safe?
}

which is definitely unsafe?

Why does `anymap::Entry` require a Clone bound?

anymap::Entry::or_insert and anymap::Entry::or_insert_with require a Clone bound on the element to be inserted.

It is unclear from both the docs and the source why that is the case, or if its intentional.

Publish a new release

Hi, @chris-morgan could you or somebody else involved in this project please publish a new release on crates.io, or possibly hand over maintainership of this project to somebody that can publish new releases?

Release anymap 0.13?

Looks like anymap could use a release so people can pick up the fix for #26, which is not in 0.12.

Split off TypeIdHasher into a separate crate

TypeIdHasher is useful for other abstractions dealing with dynamic typing.

I have copy-pasted that code into a private project of mine, because I wanted to use it to implement another collection type that is similar to AnyMap.

The collection I implemented seems generally-useful. It might be a good idea for me to publish it as a crate of my own (I don't think it belongs in anymap, as it is different enough from the purpose of this crate). However, to do that, I would need to duplicate the TypeIdHasher code from anymap. If we split that off into a separate crate, we could both depend on it instead of duplicating code.

Rustc warning for future incompatibility due to where_clauses_object_safety

Rustc throws the following error:

warning: the trait `anymap::any::CloneToAny` cannot be made into an object
  |
  = note: `#[warn(where_clauses_object_safety)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
  = note: method `clone_to_any_send` references the `Self` type in where clauses

warning: the trait `anymap::any::CloneToAny` cannot be made into an object
  |                                                                                                                  
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!                                                                                                       
  = note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>                    
  = note: method `clone_to_any_sync` references the `Self` type in where clauses                                     
                                                                                                                     
warning: the trait `anymap::any::CloneToAny` cannot be made into an object
  |                                                                                                                  
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!                                                                                                       
  = note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>                    
  = note: method `clone_to_any_send_sync` references the `Self` type in where clauses

`anymap` stopping being compilable in future?

rust-lang/rust#51443

warning: the trait `any::CloneToAny` cannot be made into an object
  --> /mnt/src/git/anymap/src/any.rs:15:8
   |
15 |     fn clone_to_any_send(&self) -> Box<CloneAny + Send> where Self: Send;
   |        ^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(where_clauses_object_safety)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
   = note: method `clone_to_any_send` references the `Self` type in where clauses

Does anymap rely on a trick deemed unsound?

Internal storage as Box<Any> prevents passing references between tasks

This is not a bug report, but a request for comments on a possibly new feature.

AnyMap internally stores data as boxed references to Any. Since Any does not carry Share and Send traits, the compiler does not allow access to the map from multiple tasks even though the original types of stored data should in principle allow it.

I have modified AnyMap by adding Send and Share bounds to Any and to type parameters of generic functions. The result is ConcurrentAnyMap, tivek/anymap@63f992f. It is safely accessible from more than just the creating task through immutable references, which makes it useful as a centralized, immutable data store. std::sync::Arc so far seems to be happy.

At this point I do not like the code duplication between AnyMap and ConcurrentAnyMap. Share+Send need to be added at several places, which is pretty intrusive. To me it seems deriving would not work (but, I have just started with Rust and maybe I'm missing something obvious).

Hope someone finds it useful, and I'd appreciate your comments.

Maintainership

Dear @chris-morgan,

I don't wish to be rude, but from the issue tracker e.g. #45 I wonder if you have had enough of maintaining this crate / real life has gotten in the way or whatever.

I have released a new version under the crate name anymap3 but I wonder whether you'd prefer for someone to look after the original crate / 'hand over' maintainership?

I noticed some users of the crate have moved to vendoring their own copy with the soundness issues fixed (and other crates have rolled their own internal ones), which overall seems bad for 'the community' as I can't just pull in their copy into my project ;-).

It's already a fairly 'complete' and maintenance-mode crate so if the idea interested you, I'd be happy to take over its keepership.

Thanks for writing this crate for us and saving us having to do it ourselves.

use stable api

We should work towards getting this to build on the "stable" releases, e.g. beta. This means we have to remove our dependence on the std_misc and core features.

  • core seems to be needed for std::raw::TraitObject which is needed for downcasting functionality.
  • std_misc seems to be needed for std::collections::hash_state::HashState and Drain

Perhaps it might be worth a look at @reem's typemap which doesn't require any features. In the worst case, we can probably salvage those features behind some sort of "nightly" feature, or better yet each one of those features under a separate feature, like "downcast" and "drain".

Future compatibility warning ("CloneToAny" cannot be made into an object)

Compiling anymap on the current nightly results in this warning: rust-lang/rust#51443

warning: the trait `any::CloneToAny` cannot be made into an object                                                                                                                
  --> src/any.rs:15:5                                                                                                                                                             
   |                                                                                                                                                                              
15 |     fn clone_to_any_send(&self) -> Box<CloneAny + Send> where Self: Send;                                                                                                    
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                    
   |                                                                                                                                                                              
   = note: #[warn(where_clauses_object_safety)] on by default                                                                                                                     
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!                                              
   = note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>                                                                                
   = note: method `clone_to_any_send` references the `Self` type in where clauses                                                                                                 

(same warning for all clone_to_any_X methods)

Add ability to check for and retrieve a value by TypeId

I'm trying to write an entity component system for game development, and I've gotten to the point where I would like to start caching lists of components for a system, so my first thought was to have a component trait that returns a list of TypeIds which describes which component types are required. Then the idea is to iterate over them when it is time to update the list of components and retrieve the value of the AnyMap by the TypeId. Currently there doesn't seem to be a way to do that exposed in your library, but it doesn't look like it would be too hard, but I'm not confident in my Rust skills yet to make a pull request myself.

My request is for a set of methods like contains_typeid, get_by_typeid, etc...

Unsound usages of unsafe implementation from `Self` to `T`

Hi, I am scanning the anymap in the latest version with my own static analyzer tool.

Unsafe conversion found at: src/any.rs

#[inline]
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T {
    &*(self as *const Self as *const T)
}

#[inline]
unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T {
    &mut *(self as *mut Self as *mut T)
}

#[inline]
unsafe fn downcast_unchecked<T: 'static>(self: Box<Self>) -> Box<T> {
    Box::from_raw(Box::into_raw(self) as *mut T)
}

This unsound implementation would create a misalignment issues, if the generics type T is not properly handled like it's other random types.

This would potentially cause undefined behaviors in Rust. If we further manipulate the problematic converted types, it would potentially lead to different consequences. I am reporting this issue for your attention.

build fails under rust 1.0

jhaddad@jhaddad-rmbp15 ~/dev/anymap$ cargo test                                                                                                                           master
   Compiling anymap v0.10.3 (file:///Users/jhaddad/dev/anymap)
src/lib.rs:4:19: 4:33 error: unstable feature
src/lib.rs:4 #![cfg_attr(test, feature(test))]
                               ^~~~~~~~~~~~~~
note: this feature may not be used in the stable release channel
error: aborting due to previous error
Could not compile `anymap`.

`any` module is no longer public

In 1.0.0-beta.2, the any module is now private and only CloneAny is exported, meaning the Downcast trait is no longer visible.

Future incompatability warnings

building anymap on nightly rust now triggers a future incompatibility warning, here's a copypasted terminal output

The package `anymap v1.0.0-beta.2` currently triggers the following future incompatibility lints:
> warning: adding an auto trait `Send` to a trait object in a pointer cast may cause UB later on
>    --> /home/draconium/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anymap-1.0.0-beta.2/src/any.rs:37:40
>     |
> 37  |                 unsafe { Box::from_raw(raw as *mut $t) }
>     |                                        ^^^^^^^^^^^^^^
> ...
> 144 | impl_clone!(dyn CloneAny + Send);
>     | -------------------------------- in this macro invocation
>     |
>     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>     = note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323>
>     = note: this warning originates in the macro `impl_clone` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> warning: adding auto traits `Send` and `Sync` to a trait object in a pointer cast may cause UB later on
>    --> /home/draconium/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anymap-1.0.0-beta.2/src/any.rs:37:40
>     |
> 37  |                 unsafe { Box::from_raw(raw as *mut $t) }
>     |                                        ^^^^^^^^^^^^^^
> ...
> 145 | impl_clone!(dyn CloneAny + Send + Sync);
>     | --------------------------------------- in this macro invocation
>     |
>     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>     = note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323>
>     = note: this warning originates in the macro `impl_clone` (in Nightly builds, run with -Z macro-backtrace for more info)

Can't make all nickel.rs

Could not compile anymap.

--- stderr
src/lib.rs:56:41: 56:44 error: explicit lifetime bound required
src/lib.rs:56 impl<'a> UncheckedAnyRefExt<'a> for &'a Any {
^~~
src/lib.rs:74:48: 74:51 error: explicit lifetime bound required
src/lib.rs:74 impl<'a> UncheckedAnyMutRefExt<'a> for &'a mut Any {
^~~
src/lib.rs:111:31: 111:34 error: explicit lifetime bound required
src/lib.rs:111 data: HashMap<TypeId, Box, TypeIdHasher>,
^~~
error: aborting due to 3 previous errors

[root@localhost nickel]# rustc -v
rustc 0.12.0-pre-nightly (5419b2ca2 2014-08-29 22:16:20 +0000)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.