mirror of
https://github.com/catppuccin/catppuccin
synced 2024-11-22 19:43:05 +00:00
b9bbd77c7f
* docs: restructure & improve contrib docs * chore: rework samples code * docs: fix capitalization & brand names * docs: PR comments & try to standardise palette vs flavor * docs: add sample-programs * docs: update submission guidelines (refs: #1821) * refactor: tidy up docs Co-authored-by: winston <hey@winston.sh>
117 lines
2.5 KiB
Rust
117 lines
2.5 KiB
Rust
#[macro_use]
|
|
extern crate log;
|
|
|
|
use std::collections::HashMap;
|
|
use std::rc::Rc;
|
|
|
|
mod stuff;
|
|
|
|
pub enum Flag {
|
|
Good,
|
|
Bad,
|
|
Ugly
|
|
}
|
|
|
|
const QUALITY: Flag = Flag::Good;
|
|
|
|
struct Table<const N: usize>([[i32; N]; N])
|
|
|
|
pub trait Write {
|
|
fn write(&mut self, buf: &[u8]) -> Result<usize>;
|
|
}
|
|
|
|
struct Object<T> {
|
|
flag: Flag,
|
|
fields: HashMap<T, u64>
|
|
}
|
|
|
|
union MyUnion {
|
|
f1: u32,
|
|
f2: f32,
|
|
}
|
|
|
|
type RcObject<T> = Rc<Object<T>>;
|
|
|
|
impl<T> Write for Object<T> {
|
|
fn write(&mut self, buf: &[u8]) -> Result<usize> {
|
|
let s = stuff::write_map(&self.fields, buf)?;
|
|
info!("{} byte(s) written", s);
|
|
Ok(s)
|
|
}
|
|
}
|
|
|
|
impl<T> Default for Object<T> {
|
|
fn default() -> Self {
|
|
Object { flag: Flag::Good, fields: HashMap::new() }
|
|
}
|
|
}
|
|
|
|
macro_rules! make_wrapper {
|
|
($wrapper_ty:ident, $base_ty:ty $(, $lu_ty:ty)?) => {
|
|
pub struct $wrapper_ty($base_ty);
|
|
impl From<$base_ty> for $wrapper_ty {
|
|
fn from(base: $base_ty) -> Self {
|
|
Self(base)
|
|
}
|
|
}
|
|
$(
|
|
impl From<$lu_ty> for $wrapper_ty {
|
|
fn from(lu: $lu_ty) -> Self {
|
|
Self(lu.get())
|
|
}
|
|
}
|
|
impl From<$wrapper_ty> for $lu_ty {
|
|
fn from(st: $wrapper_ty) -> Self {
|
|
Self::new(st.0)
|
|
}
|
|
}
|
|
)?
|
|
}
|
|
}
|
|
|
|
/* Block comment */
|
|
fn main() {
|
|
// A simple integer calculator:
|
|
// `+` or `-` means add or subtract by 1
|
|
// `*` or `/` means multiply or divide by 2
|
|
stuff::AppVersion::print();
|
|
|
|
let input = Option::None;
|
|
let program = input.unwrap_or_else(|| "+ + * - /");
|
|
let mut accumulator = 0;
|
|
|
|
for token in program.chars() {
|
|
match token {
|
|
'+' => accumulator += 1,
|
|
'-' => accumulator -= 1,
|
|
'*' => accumulator *= 2,
|
|
'/' => accumulator /= 2,
|
|
_ => { /* ignore everything else */ }
|
|
}
|
|
}
|
|
|
|
info!("The program \"{}\" calculates the value {}",
|
|
program, accumulator);
|
|
}
|
|
|
|
/// Some documentation `with a code`, *an italic text*
|
|
/// and **a bold text**
|
|
/// # Heading
|
|
/// [Rust](https://www.rust-lang.org/)
|
|
#[cfg(target_os="linux")]
|
|
unsafe fn a_function<T: 'lifetime>(count: &mut i64) -> ! {
|
|
count += 1;
|
|
'label: loop {
|
|
let str_with_escapes = "Hello\x20W\u{f3}rld!\u{abcdef}";
|
|
println!("{} {foo:<4}", str_with_escapes, foo = 42);
|
|
}
|
|
}
|
|
|
|
fn test() {
|
|
unsafe {
|
|
a_function(1);
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "disabled_feature")]
|
|
fn cfg_disabled_function() {}
|