Skip to content

How to convert BorrowTerm to String #142

Answered by pchampin
nwagner84 asked this question in Q&A
Discussion options

You must be logged in to vote

In order to make this work as is, you would need a pretty complicated type bound, but that would not really help, because not many Term implementations implement Display (which is the condition for to_string to work).

Instead, I suggest the following, where to_string is replaced with an ad-hoc function, leveraging the N-Triples serializer for all terms but IRIs.

type Input = BufReader<Box<dyn Read>>;

fn process<P>(input: Input, parser: P)
where
    P: TripleParser<Input>,
{
    let mut ts = parser.parse(input);
    let mut buf: Vec<u8> = vec![];

    let _ = ts.for_each_triple(|t| {
        let s = t.s();
        let subject: Option<String> = if s.is_iri() {
            s.iri().as_deref().

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nwagner84
Comment options

Answer selected by nwagner84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants