Skip to content

Changing Decoder trait to be more composable.#938

Merged
Narsil merged 4 commits intomasterfrom
change_decoder_trait
Mar 17, 2022
Merged

Changing Decoder trait to be more composable.#938
Narsil merged 4 commits intomasterfrom
change_decoder_trait

Conversation

@Narsil
Copy link
Copy Markdown
Contributor

@Narsil Narsil commented Mar 4, 2022

Fix #872

@Narsil Narsil requested review from McPatate and SaulLu March 4, 2022 15:11
@Narsil Narsil mentioned this pull request Mar 5, 2022
Copy link
Copy Markdown
Member

@McPatate McPatate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few questions for comprehension.

Looks good overall !

*token = format!(" {}", token);
}
if self.cleanup {
*token = cleanup(token.clone());
Copy link
Copy Markdown
Member

@McPatate McPatate Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better API-wise to pass in a reference, &token and call a .to_owned() or .clone() inside the cleanup() method ?
Feels cleaner, the responsibility of the clone is imo cleanup's.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's almost always preferable to not clone on a user's behalf and let the user decide how best to pass owned instances (if you really require ownership).

It seems maybe this function doesn't actually require ownership, I'll change to reflect that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. W/out the clone, you will have to create a new instance of a String, which is somehow similar to cloning ^^

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but at least I am following the std::str::replace signature so.. :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is the rust way, so be it 😄

@Narsil Narsil merged commit cdabef1 into master Mar 17, 2022
@SaulLu
Copy link
Copy Markdown
Contributor

SaulLu commented Mar 17, 2022

I'm sorry, I didn't have time to do a proper review. Nevertheless, I would be very interested to understand a bit better the changes that have been made 🙂

In particular, I see that the test target has changed (e.g..toEqual("hello"); to .toEqual(["h", "e", "l", "l", "o"]);): does this mean that the decode output will be different now?

@Narsil
Copy link
Copy Markdown
Contributor Author

Narsil commented Mar 17, 2022

No not the final thing, basically the output of the tokenizer will be "".join(decoder.decode(tokens)) if you will.

Only breaking changes are if you are using decoders directly.

@SaulLu
Copy link
Copy Markdown
Contributor

SaulLu commented Mar 17, 2022

Thank you very much for your answer! It's really great!

To put all the pieces together, am I right to understand that this last step is done here 😄 :

Ok(tokens.join(""))

@Narsil
Copy link
Copy Markdown
Contributor Author

Narsil commented Mar 17, 2022

Indeed ! You see Rust is not that hard ^_^

Narsil added a commit that referenced this pull request Apr 1, 2022
Narsil added a commit that referenced this pull request Apr 4, 2022
Narsil added a commit that referenced this pull request Jun 1, 2022
* Changing `Decoder` trait to be more composable.

Fix #872

* Fixing Python side.

* Fixing test.

* Updating cleanup signature, removing turbofish.
Narsil added a commit that referenced this pull request Jun 2, 2022
* Changing `Decoder` trait to be more composable. (#938)

* Changing `Decoder` trait to be more composable.

Fix #872

* Fixing Python side.

* Fixing test.

* Updating cleanup signature, removing turbofish.

* Adding `Sequence` Decoder.
Narsil added a commit that referenced this pull request Aug 23, 2022
* Changing `Decoder` trait to be more composable. (#938)

* Changing `Decoder` trait to be more composable.

Fix #872

* Fixing Python side.

* Fixing test.

* Updating cleanup signature, removing turbofish.

* Adding `Sequence` Decoder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an Sequence object to the decoders

3 participants