Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gilescope/scale-borrow
https://github.com/gilescope/scale-borrow
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/gilescope/scale-borrow
- Owner: gilescope
- Created: 2022-07-13T09:17:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-19T14:11:45.000Z (about 1 year ago)
- Last Synced: 2023-11-20T14:34:05.408Z (about 1 year ago)
- Language: Rust
- Size: 97.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# scale-borrow
Decode scale in a dynamic way but reasonably efficiently because rust can.
## Who this crate is not for
If you are targeting a few specific parachains --> use subxt
If you are targeting lots of parachains and just need something easy --> use scale-value (or https://github.com/virto-network/scales)
## Goals
* fun, pleasent
* efficient
* few deps, fast to compile (28 deps)
* wasm compatible - currently using integritee's fork of frame-metadata to achieve this.## How to use
### Pic 'n Mix
You can pick and mix the bits you care about into a struct:
```rust
descale! {
struct MyStruct<'scale> {
#[path("outer.0.val")]
named_bool: bool,
#[path("outer.1.name")]
named_bool2: &'scale str,
}
};
let my_struct = MyStruct::parse(&encoded[..], top_type_id, &types);
```alternatively there's Value.
### All the world is a `Value`
```rust
let val = ValueBuilder::parse(&encoded, top_type_id, &types);
assert_eq!(
val,
Value::Object(Box::new(vec![
("_ty", Value::U32(1)),
("val", Value::Bool(true)),
("name", Value::Str("hi val"))
]))
);
```The `_ty` field is the type of the struct. Tuples and arrays have field names 0, 1, 2 etc.
## Status
Very experimental
TODO non-panic error handling,