Skip to content

Instantly share code, notes, and snippets.

The Rust Playground rust-play

Block or report user

Report or block rust-play

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
use serde::Serialize;
pub struct CreateData {
collection: Option<String>,
data: String
}
impl<S: Serialize> From<S> for CreateData {
fn from(data: S) -> Self {
Self {
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
use serde::Serialize;
pub struct CreateBuilder {
collection: Option<String>,
data: String
}
impl<S: Serialize> From<S> for CreateBuilder {
fn from(data: S) -> Self {
Self {
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
use serde::Serialize;
pub struct CreateBuilder {
collection: Option<String>,
data: String
}
impl<S: Serialize> From<S> for CreateBuilder {
fn from(data: S) -> Self {
Self {
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
use futures;
use std::char;
use std::num;
use futures::{Future, future};
#[derive(PartialEq, Debug)]
pub enum MyError {
Utf16Error(char::DecodeUtf16Error),
ParseError(num::ParseIntError)
}
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
#[test]
fn basic_test() {
assert_eq!(day_of_year("2019-01-09".to_string()), 9);
assert_eq!(day_of_year("2019-02-10".to_string()), 41);
assert_eq!(day_of_year("2003-03-01".to_string()), 60);
assert_eq!(day_of_year("2004-03-01".to_string()), 61);
}
pub fn day_of_year(date: String) -> i32 {
let vec: Vec<&str> = date.split("-").collect();
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
for s in ["aa", "bb"].iter() {
println!("Hello, world! {}", s);
}
}
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
#[derive(Copy, Clone)] struct ZST;
fn main() {
let mut xs = [ZST; 2];
assert_eq!(
&mut xs[0] as *mut _ as usize,
&mut xs[1] as *mut _ as usize
);
}
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
let x = 5;
println!("The value of x is: {}", x);
x = 6;
println!("The value of x is: {}", x);
}
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
#![allow(dead_code)]
use std::convert::TryInto;
fn binary_search<'a>(ar:&'a [i32], elem:i32, startIndex:usize, endIndex:usize) -> isize{
let mid:usize = (startIndex + endIndex)/2;
let mut res:isize = -1;
let midelem:i32 = ar[mid];
if startIndex > endIndex {//|| (startIndex == endIndex && midelem != elem) {
@rust-play
rust-play / playground.rs
Created Sep 21, 2019
Code shared from the Rust Playground
View playground.rs
use std::cmp::Eq;
use std::collections::HashMap;
use std::hash::Hash;
pub fn occurrence_map<I, E>(target: I) -> HashMap<E, usize>
where
I: IntoIterator<Item = E>,
E: Eq + Hash,
{
let mut hash_map = HashMap::new();
You can’t perform that action at this time.