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 Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
fn main(){
let _:i8=0u8.cast();
let _:i16=0u8.cast();
let _:i32=0u8.cast();
let _:i8=0u16.cast();
let _:i16=0u16.cast();
let _:i32=0u16.cast();
let _:i8=0u32.cast();
@rust-play
rust-play / playground.rs
Created Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
trait Cast<T>{
fn cast(self)->T;
}
macro_rules! cartesian_producs_of_impls {
( row[ $($row:ty),* ] col[ $($col:ty),* ] )=>{
cartesian_producs_of_impls!{inner
state()
row[$($row),*]
col[$($col),*]
@rust-play
rust-play / playground.rs
Created Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
trait Cast<T>{}
macro_rules! cartesian_producs_of_impls {
( row[ $($row:ty),* ] col[ $($col:ty),* ] )=>{
cartesian_producs_of_impls!{inner
state()
row[$($row),*]
col[$($col),*]
}
};
@rust-play
rust-play / playground.rs
Created Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
trait Cast<T>{}
macro_rules! cartesian_producs_of_impls {
( [ $($row:ty),* ][ $($col:ty),* ] )=>{
cartesian_producs_of_impls!{inner
state()
row[$($row),*]
col[$($col),*]
}
};
@rust-play
rust-play / playground.rs
Created Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
impl Solution {
pub fn is_palindrome(s: String) -> bool {
let mut chars = s
.chars()
.filter(|c| c.is_alphanumeric())
.map(|c| c.to_lowercase());
while let (Some(next), Some(next_back)) = (chars.next(), chars.next_back()) {
if next != next_back {
return false;
}
@rust-play
rust-play / playground.rs
Created Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
let x = 1.cmp(2);
println!("{:?}", x);
}
@rust-play
rust-play / playground.rs
Created Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
#![feature(specialization)]
use std::any::type_name;
fn main(){
let _:String=false.cast();
let _:u32=0u8.cast();
}
@rust-play
rust-play / playground.rs
Created Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
fn main() {
println!("{:?}", 1u32.cmp(&2));
println!("{:?}", 1.0f32.partial_cmp(&2.0f32));
println!("{:?}", std::f32::NAN.partial_cmp(&2.032));
}
@rust-play
rust-play / playground.rs
Created Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
trait ActorMessage {
fn f();
}
struct Message;
impl<T: 'static + ActorMessage> From<T> for Message {
fn from(_: T) -> Message {
Message
}
@rust-play
rust-play / playground.rs
Created Aug 25, 2019
Code shared from the Rust Playground
View playground.rs
#![feature(rustc_attrs)]
#[rustc_layout_scalar_valid_range_start(0)]
#[rustc_layout_scalar_valid_range_end(2147483647)]
#[repr(transparent)]
struct NonNegativeI32(i32);
struct T(u32, NonNegativeI32, u32);
enum U<X> {
You can’t perform that action at this time.