Coder Social home page Coder Social logo

Comments (4)

datanel avatar datanel commented on July 19, 2024

I agree this would be helpful

from transit_model.

woshilapin avatar woshilapin commented on July 19, 2024

This message comes directly from https://github.com/CanalTP/typed_index_collection/blob/v1.1.0/src/error.rs#L7. The type of object is not known inside this generic library (we know the struct but can't really display anything). I see a few options on how to handle this problem (there might be more).

Fix in typed_index_collection

Doing this probably means to add an additional constraint on T like T: Display or T: Debug in order to be able to display the struct of the type of object.

I'm not really in favor of that solution because:

  • adding a constraint only for reporting feels wrong (and might reduce the capabilities of typed_index_collection)
  • implementation of Display or Debug is likely to not show only the type but the entire object, we don't have control on how users will implement these traits.

Introduce a Trait

To fix the previous solution, we could introduce a specific trait typed_index_collection::ObjectType for example. It's still adding a constraint to T but at least, we do not depend on implementation of Debug or Display that might not be to our taste.

Handle errors in transit_model

Most likely, we're gonna be able to create better error in transit_model. With thiserror for example, we could do something like this.

enum ObjectType {
	Network,
	Line,
	Etc,
} // Implement Display on that `enum`

#[derive(Error)]
enum TMError {
	#[error("identifier {1} of type {0} already exists")]
	IdentifierAlreadyExists(ObjectType, String, #[source] typed_index_collection::Error)
	#[error("other error")]
	OtherError,
}

Since we have plans to migrate transit_model from failure to a more modern framework (thiserror has been discussed for example), maybe this issue can be adressed once the migration happened? Note that we plan to do it but we didn't scheduled it yet and have no idea when it could happen.

from transit_model.

antoine-de avatar antoine-de commented on July 19, 2024

will be closed by hove-io/typed_index_collection#11 no?

from transit_model.

woshilapin avatar woshilapin commented on July 19, 2024

I don't think so since this piece of code is not going to output the type of object. However, we might be a step closer to achieve that.

from transit_model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.