Uuid
from the uuid
crate? Do you need some specific way of storing it in the table?
uuid
's serde
feature?
#[serde(with = "uuid::serde::compact")]
specified for that specific field, I think.
uuid::serde::compact
pub
so it's public despite being in a private module. If you mark it pub(crate)
instead, you'll see a privacy error.
extern crate
?
alloc
in no_std
environment without memory allocation, IIUC. There's a bit of discussion in rust-lang/rust#90507
smol::io::BufReader::new(smol::Unblock::new(reader))
Self
?
obj.methodA().methodB()
works if methodB
is defined on the return type of methodA
This program
struct Foo {
someString: String,
}
fn main() {
let x: Vec<Foo> = Vec::new();
x.sort_by_key(|foo| &foo.someString);
}
does not compile because
lifetime may not live long enough
returning this value requires that `'1` must outlive `'2`
I guess I should use x.sort_by()
instead in this case
does anybody know why cargo publish ignores the actual value of CARGO_PKG_VERSION
? i'm overriding the pkg version in build.rs for a project using:
println!("cargo:rustc-env=CARGO_PKG_VERSION=1.1.1");
but cargo publish seems to ignore that version and goes with the version in Cargo.toml. note in case of cargo build this is not the case.
yooo! Is there any way to extract the "index" (order of occurrence) of a struct field in a macro like this:
macro_rules! example {
(struct $name:ident {
$($field_name:ident: $field_type:ty,)*
}) => {
struct $name {
$($field_name: $field_type,)*
}
}
}
such that
example! {
struct Struct {
a: i32,
b: i32,
}
}
would have the index 0 associated to a
and 1 to b
etc. (for use in a particular impl)? =)
Hey all - got a question if someone mind helping. Got stuck on trying to understand why I get this error
error[E0499]: cannot borrow `asks` as mutable more than once at a time
--> src\domain\order.rs:148:37
|
139 | ... for lvl in asks.iter_mut() {
| ---------------
| |
| first mutable borrow occurs here
| first borrow later used here
...
148 | ... asks.push_front(new_level);
| ^^^^ second mutable borrow occurs here
Here is the actual impl
Side::ASK => {
let mut asks = self.ask;
let top_of_the_book = asks.front();
match top_of_the_book {
Some(mut level) => {
if level.price == order_entry.price {
level = &Self::update_level(level, &order_entry);
} else {
for lvl in asks.iter_mut() {
if lvl.price > order_entry.price {
let mut entries = HashMap::new();
entries.insert(order_entry.user_order_id.clone(), order_entry.clone());
let new_level = OrderLevel {
price: order_entry.price.clone(),
order_entries: entries,
};
asks.push_front(new_level);
}
if lvl.price < order_entry.price {
continue;
}
if lvl.price == order_entry.price {
lvl.order_entries.insert(order_entry.user_order_id.clone(),
order_entry.clone());
}
}
}
}
Essentially, I just want to update the order book level with the order request. But it seems like I cant simply iterate over the levels and find one to update or insert new. How would this be done in idiomatic rust?