Instantly share code, notes, and snippets.

View playground.rs
use serde::Deserializer;
use serde_derive::Deserialize;
fn non_empty_str<'de, D: Deserializer<'de>>(d: D) -> Result<Option<String>, D::Error> {
use serde::Deserialize;
let o: Option<String> = Option::deserialize(d)?;
Ok(o.filter(|s| !s.is_empty()))
}
#[derive(Debug, Deserialize)]
View playground.rs
pub trait SigningKey {
fn create_digest(&self, data: Vec<u8>) -> Vec<u8>;
}
pub struct RsaKey {
modulus: Vec<u8>,
exponent: Vec<u8>,
}
impl SigningKey for RsaKey {
View playground.rs
use std::process::Command;
fn main(){
let mut proc = Command::new("echo")
.arg("$shell")
.spawn()
.unwrap();
proc.wait().unwrap();
}
View playground.rs
fn main() {
println!("Hello, world");
println!("bad true: {}", baaad(true));
println!("bad false: {}", baaad(false));
}
fn baaad(x: bool) -> u32 {
match x {
true => 1,
View playground.rs
trait A {
fn greet(&self) {
println!("Hi! I am {}!", self.name());
}
fn name(&self) -> &str {
"A"
}
}
View playground.rs
trait A {
fn greet(&self) {
println!("Hi! I am {}!", self.name());
}
fn name(&self) -> &str {
"A"
}
}
View playground.rs
use std::ops::Add;
struct Point<T> {
x: T,
y: T,
}
impl<T: Add> Add for Point<T> {
type Output = Point<T::Output>;
View playground.rs
use std::ops::Add;
struct Point<T> {
x: T,
y: T,
}
impl<T> Add for Point<T>
where
T: Add,
View playground.rs
trait A {
fn greet(&self) {
println!("Hi! I am {}!", self.name());
}
fn name(&self) -> &str {
"A"
}
}
View playground.rs
fn main() {
println!("Hello, world!");
}