tuco

Crates.iotuco
lib.rstuco
version
sourcesrc
created_at2024-11-24 20:41:16.303259
updated_at2024-11-24 22:17:17.965748
descriptionTuco can automatically generate tuple representations of simple types. This is helpful if you want to create an API using plain types. Or if you want to provide an easy way to convert between types.
homepage
repositoryhttps://gitlab.com/johannesgotlen/tuco
max_upload_size
id1459571
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Johannes (j-gn)

documentation

README

Tuco

Tuco can automatically generate tuple representations of simple types. This is helpful if you want to create an API using plain types. Or if you want to provide an easy way to convert between types.

Using #[derive(Tuco)] Will automatically derive Tuco and generate a tuple representation of your struct and assign it to the associated type Tuco::Tuple

Tuco can be used in places where data serialization is used with some differences:

  • Conversion operations are validated at compile time.
  • Since tuples are unnamed, any matching tuple shape may be used to construct your type. No further integrity checks are applied at this time.
  • Tuco does not automatically serialize your types to string data.

Todo

  • Support structs with named fields
  • Support structs with unnamed fields
  • Support more complex structs
  • Documentation
  • Compiler errors / Tests

Example


    #[derive(Tuco, Debug)]
    struct MyStruct {
        a: i32,
        b: String,
        c: bool,
    }

    #[derive(Tuco, Debug)]
    struct MyOtherStruct {
        x: i32,
        y: String,
        z: bool,
    }

    #[derive(Tuco, Debug)]
    struct MyNestedStruct {
        x: i32,
        #[tuco]
        y: MyStruct,
        z: bool,
    }

    #[derive(Tuco, Debug)]
    struct MyOtherNestedStruct {
        x: i32,
        #[tuco]
        y: MyOtherStruct,
        z: bool,
    }

    fn nested_struct() {
        let my_nested_struct = MyNestedStruct {
            x: 10,
            y: MyStruct {
                a: 1,
                b: "qwe".to_string(),
                c: true,
            },
            z: false,
        };

        println!("{:?}", my_nested_struct);

        let my_other_struct = MyOtherNestedStruct::from_tuco(my_nested_struct);

        println!("{:?}", my_other_struct);
    } 

Output:

    MyNestedStruct { x: 10, y: MyStruct { a: 1, b: "qwe", c: true }, z: false }
    MyOtherNestedStruct { x: 10, y: MyOtherStruct { x: 1, y: "qwe", z: true }, z: false }

License

Copyright (c) 2024 Johannes Gotlén

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Commit count: 22

cargo fmt