This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Toggle Button', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn convert<S>(option: Option<S>) -> Option<String> | |
where | |
S: Into<String>, | |
{ | |
match option { | |
Some(string) => Some(string.into()), | |
None => None | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand; // 0.7.3 | |
use rand::Rng; | |
fn make_a_string_with_optional<S>(option: Option<S>) -> String | |
where | |
S: AsRef<str>, | |
{ | |
let mut s = String::from("Hello"); | |
if let Some(string) = option { | |
s.push_str(" "); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand; // 0.7.3 | |
use rand::Rng; | |
#[derive(Debug, PartialEq)] | |
struct Wrap<T> { | |
inside: T | |
} | |
impl<T> Wrap<T> { | |
fn new(inside: T) -> Wrap<T> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rand; // 0.7.3 | |
use rand::Rng; | |
#[derive(Debug, PartialEq)] | |
struct Wrap<T> { | |
inside: T | |
} | |
impl<T> Wrap<T> { | |
fn new(inside: T) -> Wrap<T> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[allow(dead_code)] | |
fn contains<'a, V, T, Q>(arr: V, value: &Q) -> bool | |
where | |
T: 'a + std::cmp::PartialEq<Q>, | |
V: std::iter::IntoIterator<Item = &'a T> | |
{ | |
arr.into_iter().any(|v| v == value) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashSet; | |
fn contains<T, Q>(arr: &HashSet<T>, value: &Q) -> bool | |
where | |
T: std::cmp::PartialEq<Q>, | |
{ | |
arr.iter().any(|v| v == value) | |
} | |
fn main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashSet; | |
fn main() { | |
let hs_str: HashSet<&str> = ["a", "b", "c"].iter().copied().collect(); | |
let hs_string: HashSet<String> = vec!["a".to_string(), "b".to_string(), "c".to_string()] | |
.into_iter() | |
.collect(); | |
let value_str = "b"; | |
let value_string = String::from(value_str); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let array_str = ["a", "b", "c"]; | |
let array_string = ["a".to_string(), "b".to_string(), "c".to_string()]; | |
let value_str = "b"; | |
let value_string = String::from(value_str); | |
let result_str = array_str.contains(&value_string); | |
let result_string = array_string.contains(&value_str); | |
let result_literal = array_string.contains("b"); |
NewerOlder