#storage #generic #type #owned #traits #alloc #helper

no-std stor

存储类型泛化的辅助工具

2个版本

0.1.1 2022年3月12日
0.1.0 2022年1月15日

#572内存管理

MPL-2.0 许可证

4KB

Stor trait定义了类型定义中使用的底层存储

use stor::Stor;

/// Generic object over storage types
enum Something<S: Stor<()>> {
  List(S::List),
  Str(S::String),
  Bytes(S::Bytes),
}

/// Owned version (requires `alloc` feature)
type SomethingOwned = Something<stor::Owned>;
let _ = SomethingOwned::Str("hello".to_string());
let _ = SomethingOwned::Bytes(vec![0xaa, 0xbb, 0xcc]);

/// Reference version
type SomethingRef<'a> = Something<stor::Ref<'a>>;
let _ = SomethingRef::Str("hello");
let _ = SomethingRef::Bytes(&[0xaa, 0xbb, 0xcc]);

/// Const N version
type SomethingConst<'a> = Something<stor::Const<3>>;
let _ = SomethingConst::Str("hello");
let _ = SomethingConst::Bytes([0xaa, 0xbb, 0xcc]);

依赖项

~645KB
~12K SLoC