Struct Key

Source
pub struct Key { /* private fields */ }
Expand description

A Key can be either a Cloud Spanner row’s primary key or a secondary index key. A Key can be used as:

  • A primary key which uniquely identifies a Cloud Spanner row.
  • A secondary index key which maps to a set of Cloud Spanner rows indexed under it.
  • An endpoint of primary key/secondary index ranges; see the KeyRange type.

Rows that are identified by the Key type are outputs of read operation or targets of delete operation in a mutation. Note that for insert/update/insert_or_update/delete mutation types, although they don’t require a primary key explicitly, the column list provided must contain enough columns that can comprise a primary key.

Keys are easy to construct. For example, suppose you have a table with a primary key of username and product ID. To make a key for this table:

use google_cloud_spanner::key::Key;

let key = Key::composite(&[&"john", &16]);

See the description of Row and Mutation types for how Go types are mapped to Cloud Spanner types. For convenience, Key type supports a range of Rust types:

  • i64 and Option are mapped to Cloud Spanner’s INT64 type.
  • f64 and Option are mapped to Cloud Spanner’s FLOAT64 type.
  • bool and Option are mapped to Cloud Spanner’s BOOL type.
  • Vec, &u8, Option<Vec> and Option<&u8> is mapped to Cloud Spanner’s BYTES type.
  • String, &str, Option, Option<&str> are mapped to Cloud Spanner’s STRING type.
  • time::OffsetDateTime and Optiontime::OffsetDateTime are mapped to Cloud Spanner’s TIMESTAMP type.
  • time::Date and Optiontime::Date are mapped to Cloud Spanner’s DATE type.
  • google_cloud_spanner::value::CommitTimestamp and Option<google_cloud_spanner::value::CommitTimestamp> are mapped to Cloud Spanner’s TIMESTAMP type.

Implementations§

Source§

impl Key

Source

pub fn new(value: &dyn ToKind) -> Key

one creates new Key

§Examples
   use google_cloud_spanner::key::Key;
   use google_cloud_spanner::statement::ToKind;
   let key1 = Key::new(&"a");
   let key2 = Key::new(&1);
Source

pub fn composite(values: &[&dyn ToKind]) -> Key

one creates new Key

§Examples
   use google_cloud_spanner::key::Key;
   use google_cloud_spanner::statement::ToKind;
   let multi_key = Key::composite(&[&"a", &1]);

Trait Implementations§

Source§

impl Clone for Key

Source§

fn clone(&self) -> Key

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 From<Key> for KeySet

Source§

fn from(key: Key) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Key

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnwindSafe for Key

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,