hecatia-elegua / bilge

Use bitsized types as if they were a feature of rust.
Apache License 2.0
171 stars 17 forks source link

Provide proper errors #87

Open apbr opened 1 year ago

apbr commented 1 year ago

Currently there is only one error when something goes wrong (The empty struct BitsError). So it is quite difficult to find out what exactly is causing the error. Please at least add some indication which struct/enum is causing the error. For example in the following code the error should point out that Bar has no variant that matches 0b0001:

    fn error_test(){
        #[bitsize(4)]
        #[derive(TryFromBits)]
        enum Foo {
            One = 0b0001,
            Two = 0b0010,
        };

        #[bitsize(4)]
        #[derive(TryFromBits)]
        enum Bar {
            Three = 0b0011,
            Four = 0b0100,
        };

        #[bitsize(8)]
        #[derive(TryFromBits)]
        struct Byte {
            foo: Foo,
            bar: Bar,
        }
        let b = Byte::try_from(0b0001_0001).unwrap();
    }
hecatia-elegua commented 11 months ago

See #40 for some previous discussion. I would love to have this too.