Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Paul Delafosse
    @oknozor
    has something changed in 1.37 regarding macros?
    Paul Delafosse
    @oknozor
    i just found out it was a versioning issue, different version of proc_macro2 were used across dependencies
    Don Gabriel
    @dbgabriel
    newbie here.. does rust compile into a raspberry pi?
    叫兽
    @arlicle
    let x:Object = Object::string_literal("Hello World!");
    Excuse me , How can I change x back to a string?
    or &str
    Sam Johnson
    @sam0x17
    I believe in that situation there is no safe way and you would have to use the unsafe mem::transmute method, which you really dont want to have to do for something simple. What you are probably trying to do is something you would use enums and pattern matching for. Look into the enum chapter in the rust book -- enums are a lot more in rust than they are in other languages -- they are essentially type unions, which is what you probably want
    @arlicle ^
    Qihe Bian
    @ufosky
    Hi, does anyone know the structure of the directory target generated by cargo?
    Mikail Bagishov
    @MikailBag
    I think it is implementation detail.
    But in general, it looks like ARCH/BUILD_PROFILE/(binaries, libs here, dependencies in deps/, incremental compilation cache in incremental/ and so on)
    richard
    @jmzhuzhonghua
    does rust have library supporting EOS operation? for example, sign one transaction of EOS
    Iddan Aaronsohn
    @iddan
    .. start
    *started to use async in a project of mine but I can’t make streams using generic lifetime strings to work. It’s in my PR. When compiled I get cryptic compile errors: iddan/minerva#1
    richard
    @jmzhuzhonghua
    who know is there base58 and base58check for bitcoin library in rust?
    Paul Delafosse
    @oknozor
    Hello, shall i rather use map on Option or if let and match ?

    i have the following example producing the same result :

        fn scan_heading(&mut self) -> Option<Node> {
            self.scan_while(|c| c == b'=')
                .map(|head_range| (*head_range.end(), self.peek()))
                .filter(|(_, peek)| *peek == Some(b' '))
                .map(|(head_level, _)| {
                    self.next();
                    self.next();
                    head_level
                })
                .map(|head_level| (head_level, self.scan_while(|c| c != b'\n')))
                .filter(|(_, content_range)| content_range.is_some())
                .map(|(head_level, content_range)| (head_level, content_range.unwrap()))
                .map(|(head_level, content_range)| Node::new(content_range, Tag::Heading(head_level)))
        }

    VS

        fn scan_heading(&mut self) -> Option<Node> {
    
            let head_level = self.scan_while(|c| c == b'=');
    
            if let Some(head_level) = head_level {
                match self.peek() {
                    Some(b' ') => {
                        self.next();
                        self.next();
                        let head_range = self.scan_while(|c| c != b'\n');
                        let len = head_level.end();
                        if let Some(head_range) = head_range {
                            return Some(Node::new(head_range, Tag::Heading(*len)));
                        }
                    }
                    _ => return None,
                };
            }
            None
        }
    appart from readability which one shall be used ?
    and maybe is there a better/more idiomatic way to do this ?
    Rob Ede
    @robjtede
    @oknozor i prefer the first one. i think you can use filter_map to remove one of the lines there
    Mohammed Abubakar
    @moh-abk
    what's the idiomatic way of copying a Vector?
    Rob Ede
    @robjtede
    @moh-abk not a Vec ? if not wheres this type from
    Mohammed Abubakar
    @moh-abk
    @robjtede yes I meant a Vec
    #[derive(Serialize, Deserialize, PartialEq, Debug)]
    enum RestaurantMenuTag {
        Name(String),
        Value(String),
    }
    #[derive(Serialize, Deserialize)]
    struct Restaurant {
        #[serde(rename = "_id")]
        pub id: Uuid,
        pub menu_tags: Vec<RestaurantMenuTag>,
    }
    move occurs because value has type std::vec::Vec<restaurants::RestaurantMenuTag>, which does not implement the Copy trait
    Rob Ede
    @robjtede
    .clone that boi
    (and also derive Clone on the enum)
    Mohammed Abubakar
    @moh-abk
    @robjtede awesome - thanks
    richard
    @jmzhuzhonghua
    i have used https://lib.rs/crates/ripemd160 but the result is not correct. who has the experience using it?
    David O'Connor
    @David-OConnor

    Hey dudes: Question regarding error handling and match arms. I've been using this pattern to exit on failure without exposing rust debugging messages:

    let var_to_set: Vec<_> = failable_func {
        Ok(a) => a,
        Err(_) => {
            abort("Problem");  // Graceful-exit function
            vec![] // Must return this to satisfy match arm in compiler, but it's a dummy
        }
    };

    How would you remove the dummy vec in the above example? What's the recommended pattern? Thank you.

    Rob Ede
    @robjtede
    @David-OConnor unreachable! macro might be what you want
    David O'Connor
    @David-OConnor
    @robjtede Thank you! That's what I'm looking for
    richard
    @jmzhuzhonghua
    does rust has hex! macro?
    Ichoran
    @Ichoran
    What would such a macro do?
    toxicafunk
    @toxicafunk
    Bewitch your computer
    Valentin
    @vroussea
    like transforming it in frog ?
    toxicafunk
    @toxicafunk
    sounds about right
    Michal 'vorner' Vaner
    @vorner
    Transforming a computer into a frog… that's what UB is for.
    Rob Ede
    @robjtede
    @jmzhuzhonghua no you'd have to use the hex crate https://docs.rs/hex/0.3.2/hex/fn.decode.html
    or just write byte arrays manually in hex format eg [0x32, 0x31]
    ....
    I just found this, will probably use it myself: https://docs.rs/hex-literal/0.2.0/hex_literal/
    richard
    @jmzhuzhonghua
    @robjtede tks. I have seen the statement " let account = self.sstore.insert_account(SecretVaultRef::Root, secret, password)?;", what's the meaning of the last char '?' ?
    Denis Lisov
    @tanriol
    Check for errors (Err in case of Result). If an error, return it immediately; otherwise evaluate to the value in Ok
    richard
    @jmzhuzhonghua
    We want to access eos using rust. does rust have eos crate just like eos.js library?
    Denis Lisov
    @tanriol
    Elliot Stern
    @PipocaQuemada
    What's the right way to write a function that returns an iterator? The inferred return type for my function is std::iter::FilterMap<std::iter::FlatMap<std::str::Chars<'_>, _, fn(char) -> std::char::ToLowercase {std::char::methods::<impl char>::to_lowercase}>, fn(char) -> std::option::Option<char> {atbash::substitute}>, but I'm assuming there's a better return type I could give it that hides the implementation details a bit better.
    bdonlan
    @bdonlan
    you could just do impl Iterator<Item=whatever>
    unless this is a method that needs to be on a trait object, in which case you'll need to either box or make a wrapper struct or something
    Rafi
    @Rafi993
    Hi there I am trying to match all occurrences of given regex r"(?i)[a-z]" it gives only my first occurrence when I do this
     match re.captures(text) {
            Some(caps) => println!("Found match: {}", caps.get(0).unwrap().as_str()),
            None => println!("No match"),
        }
    how do I get all occurrences ?
    is there equivalent to /g flag in rust ?
    I could not find any docs on that
    toxicafunk
    @toxicafunk
    get(0) seems to be three guilty party here