No description
Find a file
2022-03-27 16:11:08 +02:00
sing_macros Edited Cargo.toml to play well with crates.io 2022-03-27 16:10:03 +02:00
sing_parse Changed another Cargo.toml for the same reason. 2022-03-27 16:11:08 +02:00
sing_util Merge branch 'main' into thelie-patch-1 2022-03-27 15:39:18 +02:00
src Added copyright and license disclaimers to source files (#2) 2022-03-27 15:38:39 +02:00
.gitignore Initial commit 2022-02-19 11:37:31 +01:00
Cargo.toml Changed crate name to avoid collision on crates.io 2022-03-27 16:07:30 +02:00
LICENSE.md Renamed license file 2022-03-26 23:25:16 +01:00
README.md Update 'README.md' 2022-03-27 15:20:54 +02:00
TODO.md Update 'TODO.md' 2022-03-27 15:24:04 +02:00

Sing

Std

I/o

Negotiator

Generator

What is sing meant to be?

This crate is meant to create interfaces between traits in Rust libraries and the command line. It does this by providing two macros:

  • sing_add_trait, which acts as an attribute to a trait implementation and gathers the method signatures that are used by sing_loop!.
  • sing_loop!, which takes a trait object and serialization/deserialization functions as well as some optional parameters. It generates a loop parsing function calls coming from STDIN (or any other BufRead stream), evaluating them by calling the appropriate method on the object and returning them on STDOUT (or any other Write stream).

Usage example

use serde::{Serialize, Deserialize};
use sing::{sing_add_trait, sing_loop};

trait FruitTree {
         fn shake(&self, shakes: u32) -> Vec<Fruit>;
}

#[derive(Debug, Serialize, Deserialize)]
struct Fruit {
         fruit_type: String,
}

struct BananaTree;

#[sing_add_trait()]
impl FruitTree for BananaTree {
         fn shake(&self, shakes: u32) -> Vec<Fruit>{
                  let mut out = vec!();

                  for _ in 0..shakes {
                                out.push(Fruit{fruit_type: String::from("Banana")});
                  }
                  
                  out
         }
}

fn main() {
         let tree = BananaTree {};
         
    sing_loop!(tree, [different, ron::to_string, ron::from_str],);
}

Negotiator? Really?

Yes, it's somewhat far-fetched, but I really wanted to be able to sing and clap in my rusty command-line projects.

Why the name?

See above.