Compile-time stuff and other goodies for rustaceans πŸ¦€

Overview

πŸ₯― bagel: Always baked, never fried

Rust stable docs.rs Crates.io Discord GitHub Workflow Status

bagel is a collection of macros and other things that we frequently use at Skytable, primarily to get work done at compile-time (because we like it baked :P). This crate contains some of the stuff we use, and we'll add more of the "magic" soon.

Importing

bagel = "0.1"

What bagel can do

  • def: Use the default declaration syntax
  • Ctor: Derive constructors:
    • Full lifetimes, generics and where clause support
    • #[phantom]: Auto elide PhantomData fields
    • #[ctor_const]: Make the constructor a const fn
  • Gtor: Derive getters:
    • Full lifetimes, generics and where clause support
    • Advanced attributes: #[gtor_const], #[gtor_copy], #[gtor_skip], #[phantom] and #[gtor]
  • Stor: Derive setters
    • Full lifetimes, generics and where clause support
    • Skip setter with #[stor_skip] or #[phantom]
  • Constdef: Derive constant, compile-time default implementations. See an example here

Default declaration syntax

The default declaration syntax is an alternative way to implement defaults for your structs (and enums soon). It looks like this:

  1. Use the default trait:
    field: type
    
  2. Use your specified expression:
    field: type = expression
    

Here's an example:

use bagel::def;

def! {
    #[derive(Debug)]
    pub struct MyOven {
        starting_temperature: u8,
        increment_temp_by: u8 = 1,
        oven_name: &'static str = "my_kitchen_wifi_oven1",
        items_to_bake: [&'static str; 4] = [
            "bagels",
            "hashbrowns",
            "cookies",
            "pie",
        ],
        people_buffer: Vec<String> = vec![
            "one for Jamie".into(),
            "another for Sophie".into()
        ],
    }
}

let mut myoven = MyOven::default();

assert_eq!(myoven.starting_temperature, 0);
assert_eq!(myoven.oven_name, "my_kitchen_wifi_oven1");
assert_eq!(myoven.items_to_bake[3], "pie");
assert_eq!(myoven.people_buffer.len(), 2);

Constdef example

use bagel::Constdef;

#[derive(Constdef)]
struct Port {
    requests: usize,
    admin: bool,
}

#[derive(Constdef)]
struct PortLogger {
    ports: [Port; 65536],
    root_pid: usize,
}

const PORT_LOGGER: PortLogger = PortLogger::default();

assert_eq!(PORT_LOGGER.ports[0].requests, 0);
assert_eq!(PORT_LOGGER.ports[65535].admin, false);

License

The dough and bagel libraries are distributed under the Apache-2.0 License.

You might also like...
rust channel benchmarks to keep stat of performance of Kanal library in comparison with other competitors.
rust channel benchmarks to keep stat of performance of Kanal library in comparison with other competitors.

Rust Channel Benchmarks This is a highly modified fork of the crossbeam-channel benchmarks. to keep track of Kanal library stats in comparison with ot

Fast and simple datetime, date, time and duration parsing for rust.

speedate Fast and simple datetime, date, time and duration parsing for rust. speedate is a lax† RFC 3339 date and time parser, in other words, it pars

Parses a relative time string and returns a `Duration`

humantime_to_duration A Rust crate for parsing human-readable relative time strings and converting them to a Duration. Features Parses a variety of hu

Mindful Time Tracking: Simplify Your Focus and Boost Productivity Effortlessly.
Mindful Time Tracking: Simplify Your Focus and Boost Productivity Effortlessly.

Mindful Time Tracking: Simplify Your Focus and Boost Productivity Effortlessly. About pace is a mindful productivity tool designed to help you keep tr

Safe, comp time generated queries in rust

query_builder For each struct field following methods will be generated. All fields where_FIELDNAME_eq Numeric fields where_FIELDNAME_le where_FIELDNA

A real-time mixer

Pagana Pagana is a real-time mixer. This project is still in early stages of development and is not ready for any kind of production use or testing. D

Isn't it time to be a bit nicer to rustc?

politeness-macro Aren't we all too rude to computers? Isn't it time to bring a bit more politeness into our programming? Shouldn't we be a bit nicer t

Simple time handling in Rust

time Documentation: latest release main branch book Minimum Rust version policy The time crate is guaranteed to compile with any release of rustc from

A real-time data backend for browser-based applications.

DriftDB DriftDB is a real-time data backend for browser-based applications. For more information, see driftdb.com. Structure of this repo docs/: main

Releases(v0.1.3)
Owner
Skytable
Skytable is a free and open-source NoSQL database that aims to provide flexible data modeling at scale
Skytable
Rust crate: Overloaded Literals to construct your datatypes without boilerplate and with compile-time validation.

overloaded_literals   Overloaded Literals to construct your datatypes without boilerplate and with compile-time validation. Features Compile-time vali

Qqwy / Marten 6 Apr 14, 2023
A webring of people who make cool stuff. technology, music, art, writing, anything goes!

a webring of people who make cool stuff. technology, music, art, writing, anything goes!

Kognise 44 Dec 6, 2022
Compile time static maps for Rust

Rust-PHF Documentation Rust-PHF is a library to generate efficient lookup tables at compile time using perfect hash functions. It currently uses the C

null 1.3k Jan 1, 2023
Construct complex structures within single call + simple compile-time meta-inheritance model with mixins.

Introduction constructivism is a Rust sample-library designed to simplify the construction of structured data by defining and manipulating sequences o

polako.rs 5 Oct 24, 2023
High-order Virtual Machine (HVM) is a pure functional compile target that is lazy, non-garbage-collected and massively parallel

High-order Virtual Machine (HVM) High-order Virtual Machine (HVM) is a pure functional compile target that is lazy, non-garbage-collected and massivel

null 5.5k Jan 2, 2023
A set of Zero Knowledge modules, written in Rust and designed to be used in other system programming environments.

Zerokit A set of Zero Knowledge modules, written in Rust and designed to be used in other system programming environments. Initial scope Focus on RLN

vac 44 Dec 27, 2022
Algebraic structures, higher-kinded types and other category theory bad ideas

Algar Algebric structures, higher-kinded types and other category theory bad ideas. Yes, you'll have generalized functors, applicatives, monads, trave

Stefano Candori 3 Jan 31, 2023
A mobile application platform for tertiary students to communicate, collaborate and share ideas with each other

Qreeket (pronounced "cricket") A mobile application platform for tertiary students to communicate, collaborate and share ideas with each other. As the

Quabynah Bilson Jr. 3 May 15, 2023
Rust library for compiling and running other programs.

Exers ?? Exers is a rust library for compiling and running code in different languages and runtimes. Usage example fn main() { // Imports...

olix3001 5 Jun 10, 2023
πŸ‘Œ A smol functional language that targets other languages

ditto A small, pure functional language that targets other languages. Syntax highlighting coming soon Elevator pitch ⏱️ Ditto is a mashup of my favour

ditto 45 Dec 17, 2022