- Rust Quick Start Guide
- Daniel Arbuckle
- 301字
- 2021-06-10 19:46:00
Dependencies on libraries from crates.io
If a library that our program depends on is published on https://crates.io/, all we have to do to link it is add its linking code to the dependencies section. Let's say we want to use serde (a tool for turning Rust data into formats such as JSON and back) in our program. First, we find its linking code with: cargo search serde.
I originally found out about serde by browsing through crates.io, an exploration that I would encourage you to try as well.
This will print out a list of matches that looks something like this:
serde = "1.0.70" # A generic serialization/deserialization framework
serde_json = "1.0.24" # A JSON serialization file format
serde_derive_internals = "0.23.1" # AST representation used by Serde derive macros. Unstable.
serde_any = "0.5.0" # Dynamic serialization and deserialization with the format chosen at runtime
serde_yaml = "0.7.5" # YAML support for Serde
serde_bytes = "0.10.4" # Optimized handling of `&[u8]` and `Vec<u8>` for Serde
serde_traitobject = "0.1.0" # Serializable trait objects. This library enables the serialization of trait objects such…
cargo-ssearch = "0.1.2" # cargo-ssearch: cargo search on steroids
serde_codegen_internals = "0.14.2" # AST representation used by Serde codegen. Unstable.
serde_millis = "0.1.1" # A serde wrapper that stores integer millisecond value for timestamps and duration…
... and 458 crates more (use --limit N to see more)
The first one is the core serde library, and the linking code is the part of the line before the # symbol. All we have to do is copy and paste that into the dependencies section of Cargo.toml, and Rust will know that it should compile and link serde when it compiles our foo program. So, the dependencies section of Cargo.toml would look like this:
[dependencies]
serde = "1.0.70"
推薦閱讀
- 深入理解Android(卷I)
- Testing with JUnit
- SQL Server 2016從入門到精通(視頻教學(xué)超值版)
- Java技術(shù)手冊(原書第7版)
- Big Data Analytics
- ASP.NET 3.5程序設(shè)計與項目實踐
- Unreal Engine 4 Shaders and Effects Cookbook
- Kotlin編程實戰(zhàn):創(chuàng)建優(yōu)雅、富于表現(xiàn)力和高性能的JVM與Android應(yīng)用程序
- 新一代SDN:VMware NSX 網(wǎng)絡(luò)原理與實踐
- CoffeeScript Application Development Cookbook
- Programming with CodeIgniterMVC
- LabVIEW虛擬儀器程序設(shè)計從入門到精通(第二版)
- Java Web從入門到精通(第3版)
- 從Power BI到Analysis Services:企業(yè)級數(shù)據(jù)分析實戰(zhàn)
- Spark技術(shù)內(nèi)幕:深入解析Spark內(nèi)核架構(gòu)設(shè)計與實現(xiàn)原理