tuco-core 0.1.0

Contains the Tuco trait, used by the Tuco crate
Documentation
  • Coverage
  • 0%
    0 out of 6 items documented0 out of 6 items with examples
  • Size
  • Source code size: 4.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 109.86 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • j-gn

Tuco

Tuco is used to automatically generate tuple representations of your types. This can be helpful if you don't want to leak crate specific types of simple data through your API. 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

  • Documentation
  • Support unnamed types
  • 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.