| Crates.io | tdyne-peer-id |
| lib.rs | tdyne-peer-id |
| version | 1.0.2 |
| created_at | 2023-10-06 18:19:53.693751+00 |
| updated_at | 2023-10-06 18:42:38.627919+00 |
| description | Basic Peer ID type used across BitTorrent related libraries. |
| homepage | https://github.com/torrentdyne/tdyne-peer-id |
| repository | https://github.com/torrentdyne/tdyne-peer-id |
| max_upload_size | |
| id | 995294 |
| size | 19,079 |
tdyne_peer_id is a newtype for BitTorrent peer IDs, represented as [u8; 20].
It's intentionally kept very minimalist to minimise the possibility of backwards-incompatible
changes.
[dependencies]
tdyne-peer-id = "1"
use tdyne_peer_id::{PeerId, BadPeerIdLengthError};
fn main() {
let byte_array: &[u8; 20] = b"-TR0000-*\x00\x01d7xkqq04n";
let byte_slice: &[u8] = b"-TR0000-*\x00\x01d7xkqq04n";
let short_byte_slice: &[u8] = b"-TR0000-";
// creating a PeerId from an array is simple
let peer_id = PeerId::from(b"-TR0000-*\x00\x01d7xkqq04n");
assert_eq!(peer_id.to_string(), "-TR0000-???d7xkqq04n".to_string());
// you can also create PeerId from a byte slice if its 20 bytes long
_ = PeerId::try_from(byte_slice).expect("matching lengths");
// …if it's not, you get an error
let error = BadPeerIdLengthError(short_byte_slice.len());
assert_eq!(PeerId::try_from(short_byte_slice).expect_err("lengths don't match"), error);
}
tdyne_peer_idtdyne_peer_id_registry, peer ID
database and parsertdyne_peer_id is opensourced from TORRENTDYNE, a BitTorrent diagnostic service.