Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    lisperatu
    @lisperatu
    This is a part of some realworld problem (I handle some db fetched data).
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    np
    lisperatu
    @lisperatu
    I'm challenging myself by rewriting some critical microservices written in Python. It's my way to learn Rust.
    VinothKumar Raman
    @eventaken_twitter
    Hello,
    I have a trait which looks like this,
    trait Indicator<In, Out> {
        fn consume(&mut self, data: &Vec<In>) -> Vec<Out>;
    }
    I want to implement Add for all such indicators, such that if the Out has Add instance it should just add them
    But rust keeps cribbing about I cannot implement traits for arbitrary types if not in the same crate
    Also, the In parameter for arbitrary Indicator is not constrained. Is there a way to fix that too? Since I can't add PhantomData field for arbitrary Indicator
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    @eventaken_twitter i dont quit get what you want to do, can you show me what you have tried?
    VinothKumar Raman
    @eventaken_twitter
    I was trying to do something like this
    impl<In, N, R> Add<R> for dyn Indicator<In, N> where R: Indicator<In, N>, N : Add<N> {
        type Output = Zip<N, N, dyn Indicator<In, N>, R, fn(N, N)>;
    
        fn add(self, rhs: R) -> Self::Output {
            Zip {
                left: self,
                right: rhs,
                zipper: Add::add,
                left_buffer: VecDeque::new(),
                right_buffer: VecDeque::new()
            }
        }
    }
    Also this, impl<In, N, I, R> Add<R> for I where I : Indicator<In, N>, R: Indicator<In, N>, N : Add<N>
    Neither works
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    woudl that not be something like
    impl<T, In, N, R> Add<R> for T where T: Indicator<In, N>, R: Indicator<In, N>, N: Add<N>
    ohh wait just noticed you said the same, my bad
    what error do you get for impl<In, N, I, R> Add<R> for I where I : Indicator<In, N>, R: Indicator<In, N>, N : Add<N> as i dont have anywere to check it
    VinothKumar Raman
    @eventaken_twitter
    Only traits in current trait can be implemented for arbitrary types
    Also
    unconstrained type parameter both for In and N
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    ahh so you are crossing 2 packages?
    VinothKumar Raman
    @eventaken_twitter
    No Add is not in my package right?
    It was complaining that I cannot implement Add since its not in my crate
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    thats correct thats not possible
    VinothKumar Raman
    @eventaken_twitter
    Is there any other way I can overload + for this?
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    I tend to use a wrapper trait to do similar things
    VinothKumar Raman
    @eventaken_twitter
    How do you do that?
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    will have to try it out its a long time since i did last,
    VinothKumar Raman
    @eventaken_twitter
    Oh okay I will search for it, but thanks for the hint
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    what crate is Add from? will give you a hand as soon as i have fed my daughter XD
    VinothKumar Raman
    @eventaken_twitter
    @KatsuoRyuu I figured what you meant by wrapper
    I defined,
    struct Indicator<In, Transducer, Out> {
        input: PhantomData<In>,
        output: PhantomData<Out>,
        processor: Transducer
    }
    and Transducer as the original Indicator. I suppose every problem can indeed be solved with another level of indirection
    BTW, Add is from standard library
    That's the way you overload the operator +
    But thanks for the hint
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    yes correct, sorry if i was not clear on it ;)
    Piyush 🌱
    @shiftcommand_twitter
    Hello Everyone , I have been trying to learn Rust / Diesel and have taken up some pet project to do so. I was trying to convert the following to Diesel , currently I am clueless can someone please point me to a direction ?
    select p.id,name, gender, p.email, phone, age, photo , industry, tags, country , area, twitter, user_list_id from people  
    as p left join
    (
        select * from list_people lp 
            inner join user_list ul on lp.user_list_id = ul.id 
            inner join users u on ul.user_id = u.id  
            where u.id = 1
    ) g on p.id = g.people_id
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    Thats from diesel, i would suggest trying the diesel-rs/diesel gitter and https://github.com/diesel-rs/diesel/discussions/categories/q-a
    Piyush 🌱
    @shiftcommand_twitter
    Ahh of-course , Thank you 🙏
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    np, they are usually really good at helping out as Diesel can be a little complex ;)
    Piyush 🌱
    @shiftcommand_twitter
    I understand :)
    Proem Meas
    @measproem

    Dear All,
    I am new on Rust, I want using Serde Destabilize struct that contain field uuid (byte) any help to archive that

    `pub fn decode_serde<'de, T, R>(r: R) -> io::Result<T>
    where
        T: Deserialize<'de>,
        R: io::Read,
    {
        Deserialize::deserialize(&mut Deserializer::new(r)).map_err(map_err_to_io)
    }`

    With Deserialize::deserialize can modified to support uuid ?

    tanriol
    @tanriol:matrix.org
    [m]
    What do you mean by field uuid?
    Proem Meas
    @measproem
    Let me quick explain my case, I am using Actix web framework, by connect to database Tarantool, assume tble_user fields id(uuid), first_name, last_name,email. After I execute query select the result response need to use Serde Deserialize to my Struct all field success except field id contain data type uuid can't deserialize
    I am using this crate :https://github.com/zheludkovm/RustyTarantool/blob/master/src/tarantool/tools.rs#L24
    tanriol
    @tanriol:matrix.org
    [m]
    Do you mean Uuid from the uuid crate? Do you need some specific way of storing it in the table?
    Have you enabled the uuid's serde feature?
    Proem Meas
    @measproem
    Yes, I am using Uuid from uuid crate . I want the result from database deserialize to my struct by support uuid
    Yes uuid's serde feature
    tanriol
    @tanriol:matrix.org
    [m]
    Sounds like you may need this, not sure exactly... you may need to experiment a bit.
    1 reply