Crates.io | with-id |
lib.rs | with-id |
version | 1.0.2 |
source | src |
created_at | 2023-03-20 11:06:19.232098 |
updated_at | 2023-03-20 12:22:31.879357 |
description | Simple trait providing method for getting string id from struct |
homepage | |
repository | https://github.com/ArseniiRudenko/with-id |
max_upload_size | |
id | 815154 |
size | 3,001 |
Small crate containing a couple of traits providing id method. Useful when you need to limit some other trait to types that have id field.
[dependencies]
with-id = {version = "1", features=["derive"]}
use with_id::WithRefId;
#[derive(WithRefId)]
struct Record{
id: String,
some_other: String
}
trait TakesRecord<T: WithRefId<str>>{
fn get_endpoint(&self,record:T)->String;
}
struct Client{
url:String
}
impl TakesRecord<Record> for Client{
fn get_endpoint(&self,record:Record)->String{
self.url.to_owned()+record.id()
}
}