#id #str #string

with-id

Simple trait providing method for getting string id from struct

1 stable release

1.0.2 Mar 20, 2023

#1845 in Rust patterns

Download history 17/week @ 2024-02-23 16/week @ 2024-03-01 2/week @ 2024-03-08 2/week @ 2024-03-15 47/week @ 2024-03-29 6/week @ 2024-04-05

53 downloads per month
Used in openai-req

MIT license

4KB

With id

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.

Usage

[dependencies]
with-id = {version = "1", features=["derive"]}

Example

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()
    }
}

Dependencies

~125KB