Struct Prose

Source
pub struct Prose {
    pub text: String,
    pub url: String,
    pub lang: String,
    pub licence: String,
}
Expand description

A piece of prose taken from somewhere, with what its licence obliges.

One value, not four fields. Wikipedia is CC BY-SA: the text may be reused, and attribution has to travel with it. A text field beside a separate optional url would make it possible — and therefore eventually certain — to hold the words without the credit: one code path that fills the first and forgets the second, one export that copies one and not the other, and the project is quietly out of compliance.

So they are the same value. There is no way to store the sentence without storing where it came from, in which language, and under what terms, because the type does not offer one.

Fields§

§text: String

The words themselves.

§url: String

The page they came from, which is the attribution a reader can follow.

§lang: String

Language code of that page, so a reader knows what they are getting.

§licence: String

The licence, named as the source names it — CC BY-SA 4.0.

Stored per record, not looked up from a constant. It is the same string for every Wikipedia article today, so carrying a copy on each row looks like waste — about twenty-four bytes, ten kilobytes over a large library. It buys two things that a constant read at display time cannot.

It is a fact about the fetch, like SourceRecord::fetched_at: it says what these words were taken under, not what the current build believes they would be taken under now. Wikimedia has already moved once — CC BY-SA 3.0 to 4.0 — and with a constant that upgrade silently relabels every paragraph fetched before it.

And Prose is not Wikipedia’s. It is prose with its terms, so the next source of a biography — a plugin, a label, a discography site under quite different terms — files it in this same field, and the record says which. Moving the licence out to the source that usually supplies it would make the second source a special case of the first.

Implementations§

Source§

impl Prose

Source

pub fn credit(&self) -> String

The line that has to appear wherever the text does.

The language is named, and that is not decoration. This text is fetched in one language and kept in one language, so a reader who wanted French and is reading English has no way to tell whether their preference was ignored, whether the article does not exist in French, or whether the prose was fetched before they expressed a preference at all. The field was stored from the first version and displayed nowhere — the same dead end source_id and the fingerprints had. Now the screen says which language it is, and the way to ask for another is one line below.

Trait Implementations§

Source§

impl Clone for Prose

Source§

fn clone(&self) -> Prose

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Prose

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Prose

Source§

fn eq(&self, other: &Prose) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Prose

Source§

impl StructuralPartialEq for Prose

Auto Trait Implementations§

§

impl Freeze for Prose

§

impl RefUnwindSafe for Prose

§

impl Send for Prose

§

impl Sync for Prose

§

impl Unpin for Prose

§

impl UnwindSafe for Prose

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,