5个版本
| 0.1.4 | 2021年1月30日 | 
|---|---|
| 0.1.3 | 2021年1月22日 | 
| 0.1.2 | 2021年1月21日 | 
| 0.1.1 | 2021年1月21日 | 
| 0.1.0 | 2021年1月21日 | 
#2157 在 编码
被  4 crates 使用
17KB
292 行
Try<Encoding>From (try_encoding_from)
此库包含了一个方便的API包装器,灵感来源于TryFrom和TryInto特质,用于serde_json、serde_yaml和serde_cbor。
serde、serde_json、serde_yaml和serde_cbor包包含在内,并可以在特征标志json、yaml和cbor下使用。请参阅编码模块的API以查看可用的可选特质定义。注意:使用json、yaml或cbor功能将需要包含serde包,因为Serialize、Deserialize和DeserializeOwned特质对于库的编译是必需的。
示例
use try_encoding_from::TryJsonFrom;
use btree_graph::{BTreeGraph, AddVertex, AddEdge, Vertices};
fn main() {
    // Add three nodes.
    let mut graph: BTreeGraph<usize, usize> = BTreeGraph::new();
    graph.add_vertex(0);
    graph.add_vertex(1);
    graph.add_vertex(2);
    // Check there is indeed three nodes.
    assert_eq!(graph.vertices().len(), 3);
    // Add an edge (0, 1) = 2, (1, 2) = 3, and (0, 2) = 4.
    graph.add_edge(0, 1, 2).unwrap();
    graph.add_edge(1, 2, 3).unwrap();
    graph.add_edge(0, 2, 4).unwrap();
    let json_string: String = String::try_json_from(graph)?;
    assert_eq!(json_string, String::from("{\"vertices\":{\"0\":[2,4],\"1\":[3],\"2\":[]},\"edges\":{\"2\":[0,1],\"3\":[1,2],\"4\":[0,2]}}"));
}
用法
将以下内容添加到您的Cargo.toml文件中
[dependencies]
try_encoding_from = "0.1.3"
API
请参阅API以获取可用方法的全列表。
许可证
此作品的双重许可MIT OR Apache-2.0。
依赖项
~0–600KB
~13K SLoC