Skip to content

Instantly share code, notes, and snippets.

@NebulaFox
NebulaFox / main.dart
Created October 7, 2020 04:20
TextField does not behave correctly
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
@NebulaFox
NebulaFox / main.dart
Last active October 4, 2020 19:32
Showing ToggleButtons does not remove border
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Toggle Button',
@NebulaFox
NebulaFox / playground.rs
Created March 20, 2020 03:40
variable decleration
fn convert<S>(option: Option<S>) -> Option<String>
where
S: Into<String>,
{
match option {
Some(string) => Some(string.into()),
None => None
}
}
@NebulaFox
NebulaFox / playground.rs
Created March 20, 2020 02:59
strings wrapped up in Option
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(" ");
@NebulaFox
NebulaFox / playground.rs
Created March 20, 2020 01:12
Wrap type implementing AsRef<str>
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> {
@NebulaFox
NebulaFox / playground.rs
Created March 20, 2020 01:01
Wrap type implementing Into<String>
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> {
@NebulaFox
NebulaFox / playground.rs
Created March 18, 2020 19:30
Unify HashSet contains and Vec contains solutions
#[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)
}
@NebulaFox
NebulaFox / playground.rs
Last active March 18, 2020 18:43
HashSet contains solution
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() {
@NebulaFox
NebulaFox / playground.rs
Last active March 18, 2020 18:17
HashSet contains problem
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);
@NebulaFox
NebulaFox / playground.rs
Last active March 18, 2020 18:02
Vec contains problem
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");