dgkf / dgkf/R

Internal Character representation should maybe use `Rc<String>` instead of `String`

Open
#132 1 comment 0 reactions 0 assignees View on GitHub
meta-discussion theme-internals type-design
Dominant language
Rust
Stars
145
Forks
5
PR merge metrics
No merged PRs in 30d

Description

The current character representation defines a character element as

```rust
pub type Character = OptionNA;
```

To my understanding, this makes it rather difficult to iterate over references (i.e. iterators yielding `&OptionNA` or `Ref<'_, OptionNA>`). This is, because the lifetime of yielded elements in iterators can only be related to the lifetime of the reference of the parameter of the input lifetime of `fn (&mut self) -> &T` and not of the iterator itself. There are iterators (so called "lending iterators") that support it, see e.g. https://docs.rs/lending-iterator/latest/lending_iterator/, but they have a limited feature set.
If one does not want to go down the lending iterator route, the iterator then needs to yield `OptionNA`, which will require cloning each `OptionNA`.

To address this, one can wrap the character elements in an `Rc`, i.e. `OptionNA>` or `Rc>`. Then iterators over character vectors can easily yield owned elements without cloning the internal `String`.

Therefore, I suggest to replace the above `Character` definition with either

```rust
pub type Character = OptionNA>
```

or

```rust
pub type Character = Rc>
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.