repository

Crates.iorepository
lib.rsrepository
version0.0.2
sourcesrc
created_at2020-08-23 13:47:49.204239
updated_at2020-09-11 01:24:43.360347
descriptionA repository for all kinds of entities.
homepage
repositoryhttps://github.com/crlf0710/repository-rs
max_upload_size
id279829
size50,175
Charles Lew (crlf0710)

documentation

README

Repository: A repository for all kinds of entities.

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.

Usage example:

// 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);

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Commit count: 35

cargo fmt