pchampin / sophia_rs

Sophia: a Rust toolkit for RDF and Linked Data
Other
210 stars 23 forks source link

More factories #82

Closed MattesWhite closed 3 years ago

MattesWhite commented 3 years ago

The TermFactory-trait is useful in many occasions where someone tries to build dynamically new terms (especially blank nodes).

However, for now only factories for Rc<str> and Arc<str> where provided. This PR add a SimpleFactory when expected TermData can be directly converted, e.g. String to Box<str> and an implementation for closures.

In addtion, I did a small simplification of the TermFactory trait.

MattesWhite commented 3 years ago

Yes, indeed I have a requirement for something to create new RDF terms, e.g. when I turn the results of the RDF test suite into RDF itself or more generally try to do some object-triple-mapping.

Another use case is creating new blank nodes when parsing [] terms in Turtle. But that can be handled by a dedicated crate.

Change TermFactory

Given the new TTerm trait, it is right to go for a Term agnostic factory, especially agnostic of TermData. However, I'd rather stick with the factory pattern.

The thing with a factory is that we still have a dedicated entity. The CreateableTerm solution you proposed has only static methods (no self argument). This makes it quite difficult to implement the trait for a TermCache. In addition, the naming CreateableTerm would not fit that well with an ArcTermCache.

Conclusion

Due to the need to change the current TermFactory trait I'd close this PR and prepare a new one with a sophia_term::Term agnostic factory.

MattesWhite commented 3 years ago

As announced this PR is closed in favour of #89.