Skip to content

Instantly share code, notes, and snippets.

View kivimango's full-sized avatar

Kivimango kivimango

  • EU
View GitHub Profile
@kivimango
kivimango / gist:503c7c6cf27864fa9fd4db4a05ff7caf
Last active March 25, 2023 23:43
Converting between different String types in Rust
let s: String = ...
let st: &str = ...
let u: &[u8] = ...
let b: [u8; 3] = b"foo"
let v: Vec<u8> = ...
let os: OsString = ...
let ost: OsStr = ...
From To Use Comment
---- -- --- -------
https://medium.com/digitalfrontiers/rust-dynamic-dispatching-deep-dive-236a5896e49b
https://www.lpalmieri.com/posts/skeleton-and-principles-for-a-maintainable-test-suite/#why-don-t-we-write-tests
https://brson.github.io/2017/07/10/how-rust-is-tested
https://quick-lint-js.com/blog/cpp-vs-rust-build-times/
widget!(FineDialog {
background: Brush,
body_background: Brush,
body_foreground: Brush,
body_font: String,
body_font_size: f64,
body_padding: Thickness,
border_brush: Brush,
border_radius: f64,
@kivimango
kivimango / image.rs
Created October 29, 2020 09:00
Image resize draft
use std::{fmt, path::Path};
use image::{GenericImageView, imageops::FilterType};
use crate::RenderTarget;
#[derive(Clone, Default)]
pub struct Image {
render_target: RenderTarget,
source: String,
}
@kivimango
kivimango / Cargo.toml
Last active September 23, 2020 17:12
Calendar latest
[package]
name = "calendar"
version = "0.1.0"
authors = ["kivimango <balazsviktor23@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
orbtk = { git = "https://github.com/redox-os/orbtk.git", branch = "develop" }
use orbtk::prelude::*;
use std::collections::HashMap;
use orbtk::shell::WindowRequest;
static ID_CHECK_POLICY_NUMBER: &'static str = "ID_CHECK_POLICY_NUMBER";
static PGBAR_ID: &'static str = "PGBAR_ID";
enum Action {
ParsePolicyNumber
}
@kivimango
kivimango / directory_list.rs
Created June 10, 2020 08:11
directory_list multiple mutable borrows
use crate::core::list_dir::{list_dir, DirContent};
use orbtk::prelude::*;
use orbtk::behaviors::MouseBehavior;
use orbtk::shell::{Key, KeyEvent};
use std::path::PathBuf;
type FileList = Vec<DirContent>;
//const DIRECTORY_LIST_ID: &'static str = "directory_list";
const CWD_LABEL_ID: &'static str = "path_label";
@kivimango
kivimango / directory_list.rs
Created June 6, 2020 09:01
twin_commander_listview_selection
use crate::core::list_dir::{list_dir, DirContent};
use orbtk::prelude::*;
use std::path::PathBuf;
use orbtk::shell::{Key, KeyEvent};
use orbtk::behaviors::MouseBehavior;
type FileList = Vec<DirContent>;
const DIRECTORY_LIST_ID: &'static str = "directory_list";
const CWD_LABEL_ID: &'static str = "path_label";
@kivimango
kivimango / gist:57fd669c44307021d29cd16d85bccb09
Created May 27, 2020 22:47
print a formatted lists of files in rust
let files = list_dir(Path::new("."));
match files {
Ok(content) => {
println!("{0: <35} | {1: <10} | {2: <10} | {3: <10}",
"Name", "Extension", "Created", "Size");
for f in content {
println!("{0: <35} | {1: <10} | {2: <10} | {3: <10}", f.name, f.ext, f.date, f.size);
}
}
fn main() {
println!("Hello, world!");
let columns = vec!("Name", "Name", "ext", "Size", "Date", "Attr");
let row1 = MyData {
name: "/home".parse().unwrap(),
ext: "".parse().unwrap(),
size : 348763,
date: "2014.11.04 14:32".parse().unwrap(),
attrs: "r---".to_string(),