| Crates.io | repository |
| lib.rs | repository |
| version | 0.0.2 |
| created_at | 2020-08-23 13:47:49.204239+00 |
| updated_at | 2020-09-11 01:24:43.360347+00 |
| description | A repository for all kinds of entities. |
| homepage | |
| repository | https://github.com/crlf0710/repository-rs |
| max_upload_size | |
| id | 279829 |
| size | 50,175 |
Repository provides storage for multiple data types, it provides
its own kind of index handle called EntityId and its own kind of typed
handle called EntityPtr<T>. With these handles it allows the values
resident in the same Repository to reference each other easily.
The data behind the EntityPtr<T> handle can be accessed when you have
a corresponding reference to the whole repository.
The data behind the EntityId handle can be accessed when you know its
type and have a corresponding reference to the whole repository.
// create a repository.
let mut repo = Repo::new();
// insert and retrieve a pointer handle.
let a = repo.insert(42i32);
assert_eq!(42i32, *a.get_ref(&repo).unwrap());
// insert and retrieve a index handle.
let b = repo.insert_for_id(42i32);
// downcast from index handle to pointer handle.
let b_ptr = b.cast_ptr::<i32>(&repo).unwrap();
assert_eq!(42i32, *b_ptr.get_ref(&repo).unwrap());
// downcasting fails when type is incorrect.
let b_wrong_ptr = b.cast_ptr::<u32>(&repo);
assert_eq!(None, b_wrong_ptr);