Skip to main content

Layout

Struct Layout 

Source
#[non_exhaustive]
pub struct Layout { pub name: &'static str, pub entries: &'static [Entry], pub decimal_separator: char, pub alternates: &'static [(char, &'static str)], }
Expand description

A keyboard layout: a table of positions, and the decimal key’s character.

#[non_exhaustive], because a layout is a description of a keyboard and keyboards keep turning out to have one more thing about them worth writing down. This crate has now added a field twice — the decimal separator, then the alternates — and the second one broke every struct literal building a Layout outside it. There is no third time: an added field costs nobody a compile error from here.

It also says something true about the type. These tables are the layouts that ship; a caller wanting another writes one here, where the tests that walk every layout and check it can type its own alphabet will walk that one too. A Layout assembled elsewhere would have skipped them.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: &'static str

Human-readable name, for logging what a device is being read as.

§entries: &'static [Entry]

Positions, in no particular order. Looked up by linear scan: about fifty comparisons, at most a few times per second, against the complexity of keeping a sorted table sorted.

§decimal_separator: char

What the numpad’s decimal key types. . in most of the world, , in most of Europe.

§alternates: &'static [(char, &'static str)]

Accented characters a position can offer when held, by base character.

A fact about the layout rather than about any keyboard: which letters an o should offer depends on what the writer of this language reaches for, and a keyboard reading them from here switches its offers when it switches layout, for free.

Keyed by the lower-case base character rather than by position, because that is what makes the table readable and what makes KeyCode::Semicolon offer ø’s relatives on Norwegian and ;’s nothing on US, without the table having to know where the layout put anything.

The base character is not repeated in its own list — a keyboard shows the key itself alongside these.

Implementations§

Source§

impl Layout

Source

pub fn alternates_for(&self, base: char) -> impl Iterator<Item = char> + use<'_>

What holding a position offers, if anything.

Asked with the character the key currently types rather than its position, so a shifted key offers the shifted forms: hold O and the answer is ÖØÓ, not öøó. Empty for a position with nothing to offer, which is most of them.

The case follows the base: a table written in lower case answers in upper for an upper-case base, so one table serves both.

Source

pub fn entry(&self, code: KeyCode) -> Option<&'static Entry>

What this layout puts on one position, at each of its four levels.

None for a position no layout describes. Positions the layout does not list fall back to the shared letter table, so a layout only spells out what it moves — which is why Layout::entry answers for KeyCode::A on a table that never mentions it.

An on-screen keyboard reads this to letter its keys: the caller picks the level from the modifiers it is currently showing.

Trait Implementations§

Source§

impl Clone for Layout

Source§

fn clone(&self) -> Layout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Layout

Source§

impl Debug for Layout

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.

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.

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
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.