Either?
Either here since by convention one "side" is used for errors
Hello!
I have a tiny question about the tokio library.
I'm trying to find a more idiomatic way to do the following:
let msg: Result<WsMsg, WebSocketError> = serde_json::from_str(&msg)
.map_err(|e| ResponseError("The server has replied with an unknown message"));
if msg.is_err() {
return err(msg.unwrap_err());
}
let msg = msg.unwrap();I've tried using the ? operator on the FuturesResult returned by err, but for some reason FuturesResult doesn't implement the Try trait.
Hello Rustaceans! To implement Clone for a Box of a trait instance with a specific lifetime, what's the best practice? Example:
trait SomeTrait: Clone + Sized {
fn some_method(&self) -> &bool;
}
#[derive(Clone)]
struct SomeStruct {
pub val: bool,
}
impl SomeTrait for SomeStruct {
fn some_method(&self) -> &bool {
&self.val
}
}
struct OtherStruct<'a> {
pub some_box: Box<'a + SomeTrait>,
}
fn main() {}This code will produce this:
error[E0038]: the trait `SomeTrait` cannot be made into an object
--> src/main.rs:16:5
|
16 | pub some_box: Box<'a + SomeTrait>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SomeTrait` cannot be made into an object
|
= note: the trait cannot require that `Self : Sized`
Vec with different implementations of SomeTrait?
: Clone + Sized bound, your code will compile as expected, but I'm not sure if you need it too...
clone method to your trait
trait SomeTrait {}
struct Foo {}
impl SomeTrait for Foo {}
struct Bar {}
impl SomeTrait for Bar {}
struct SomeStruct<'a> {
some_attr: Vec<Box<'a + SomeTrait>>,
}
impl<'a> SomeStruct<'a> {
pub fn some_method(&self) -> Vec<Box<SomeTrait>> {
self.some_attr.clone();
}
}
&[Box<SomeTrait>] and use it where possible
derive(Clone): https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4e96609149bce63ae5ad428db14413c3
cargo bench sscal is as fast as openblas but when I run RUSTFLAGS="-C target-cpu=native" cargo bench It is 2x slower than openblas. Does anyone know why target-cpu=native is slowing my code?