pub fn new(key_string: impl AsRef<str>) -> Self {
        let input_key_material = key_string.as_ref();

        // HKDF was chosen because it is designed to concentrate the entropy in a variable-length
        // input key and produce a higher quality but reduced-length output key with a
        // well-specified and reproducible algorithm.
        //
        // Granted, the input key is usually meant to be pseudorandom and not human readable,
        // but we're not trying to produce an unguessable value by any means; just one that's as
        // unlikely to already be in use as possible, but still deterministic.
        //
        // SHA-256 was chosen as the hash function because it's already used in the Postgres driver,
        // which should save on codegen and optimization.

        // We don't supply a salt as that is intended to be random, but we want a deterministic key.
        let hkdf = Hkdf::<Sha256>::new(None, input_key_material.as_bytes());

        let mut output_key_material = [0u8; 8];

        // The first string is the "info" string of the HKDF which is intended to tie the output
        // exclusively to SQLx. This should avoid collisions with implementations using a similar
        // strategy. If you _want_ this to match some other implementation then you should get
        // the calculated integer key from it and use that directly.
        //
        // Do *not* change this string as it will affect the output!
        hkdf.expand(
            b"SQLx (Rust) Postgres advisory lock",
            &mut output_key_material,
        )
        // `Hkdf::expand()` only returns an error if you ask for more than 255 times the digest size.
        // This is specified by RFC 5869 but not elaborated upon:
        // https://datatracker.ietf.org/doc/html/rfc5869#section-2.3
        // Since we're only asking for 8 bytes, this error shouldn't be returned.
        .expect("BUG: `output_key_material` should be of acceptable length");

        // For ease of use, this method assumes the user doesn't care which keyspace is used.
        //
        // It doesn't seem likely that someone would care about using the `(int, int)` keyspace
        // specifically unless they already had keys to use, in which case they wouldn't
        // care about this method. That's why we also provide `with_key()`.
        //
        // The choice of `from_le_bytes()` is mostly due to x86 being the most popular
        // architecture for server software, so it should be a no-op there.
        let key = PgAdvisoryLockKey::BigInt(i64::from_le_bytes(output_key_material));

        log::trace!(
            "generated {:?} from key string {:?}",
            key,
            input_key_material
        );

        Self::with_key(key)
    }
/// Construct a `PgAdvisoryLock` using the given string as a key.
///
/// This is intended to make it easier to use an advisory lock by using a human-readable string
/// for a key as opposed to manually generating a unique integer key. The generated integer key
/// is guaranteed to be stable and in the single 64-bit integer keyspace
/// (see [`PgAdvisoryLockKey`] for details).
///
/// This is done by applying the [Hash-based Key Derivation Function (HKDF; IETF RFC 5869)][hkdf]
/// to the bytes of the input string, but in a way that the calculated integer is unlikely
/// to collide with any similar implementations (although we don't currently know of any).
/// See the source of this method for details.
///
/// [hkdf]: https://datatracker.ietf.org/doc/html/rfc5869
/// ### Example
/// ```rust
/// # extern crate sqlx_core as sqlx;
/// use sqlx::postgres::{PgAdvisoryLock, PgAdvisoryLockKey};
///
/// let lock = PgAdvisoryLock::new("my first Postgres advisory lock!");
/// // Negative values are fine because of how Postgres treats advisory lock keys.
/// // See the documentation for the `pg_locks` system view for details.
/// assert_eq!(lock.key(), &PgAdvisoryLockKey::BigInt(-5560419505042474287));
/// ```
Construct a `PgAdvisoryLock` using the given string as a key.
This is intended to make it easier to use an advisory lock by using a human-readable string
for a key as opposed to manually generating a unique integer key. The generated integer key
is guaranteed to be stable and in the single 64-bit integer keyspace
.

This is done by applying the [Hash-based Key Derivation Function (HKDF; IETF RFC 5869)][hkdf]
to the bytes of the input string, but in a way that the calculated integer is unlikely
to collide with any similar implementations (although we don't currently know of any).
See the source of this method for details.


Construct a ` PgAdvisoryLock ` using the given string as a key . This is intended to make it easier to use an advisory lock by using a human - readable string for a key as opposed to manually generating a unique integer key . The generated integer key is guaranteed to be stable and in the single 64 - bit integer keyspace . This is done by applying the [ Hash - based Key Derivation Function ( HKDF ; IETF RFC 5869 ) ] [ hkdf ] to the bytes of the input string but in a way that the calculated integer is unlikely to collide with any similar implementations ( although we don ' t currently know of any ) . See the source of this method for details .
pub fn new(key_string: impl AsRef<str>) -> Self {
        let input_key_material = key_string.as_ref();
        // HKDF was chosen because it is designed to concentrate the entropy in a variable-length
        // input key and produce a higher quality but reduced-length output key with a
        // well-specified and reproducible algorithm.
        //
        // Granted, the input key is usually meant to be pseudorandom and not human readable,
        // but we're not trying to produce an unguessable value by any means; just one that's as
        // unlikely to already be in use as possible, but still deterministic.
        //
        // SHA-256 was chosen as the hash function because it's already used in the Postgres driver,
        // which should save on codegen and optimization.
        // We don't supply a salt as that is intended to be random, but we want a deterministic key.
        let hkdf = Hkdf::<Sha256>::new(None, input_key_material.as_bytes());
        let mut output_key_material = [0u8; 8];
        // The first string is the "info" string of the HKDF which is intended to tie the output
        // exclusively to SQLx. This should avoid collisions with implementations using a similar
        // strategy. If you _want_ this to match some other implementation then you should get
        // the calculated integer key from it and use that directly.
        //
        // Do *not* change this string as it will affect the output!
        hkdf.expand(
            b"SQLx (Rust) Postgres advisory lock",
            &mut output_key_material,
        )
        // `Hkdf::expand()` only returns an error if you ask for more than 255 times the digest size.
        // This is specified by RFC 5869 but not elaborated upon:
        // https://datatracker.ietf.org/doc/html/rfc5869#section-2.3
        // Since we're only asking for 8 bytes, this error shouldn't be returned.
        .expect("BUG: `output_key_material` should be of acceptable length");
        // For ease of use, this method assumes the user doesn't care which keyspace is used.
        //
        // It doesn't seem likely that someone would care about using the `(int, int)` keyspace
        // specifically unless they already had keys to use, in which case they wouldn't
        // care about this method. That's why we also provide `with_key()`.
        //
        // The choice of `from_le_bytes()` is mostly due to x86 being the most popular
        // architecture for server software, so it should be a no-op there.
        let key = PgAdvisoryLockKey::BigInt(i64::from_le_bytes(output_key_material));
        log::trace!(
            "generated {:?} from key string {:?}",
            key,
            input_key_material
        );
        Self::with_key(key)
    }
pub fn new ( key_string : impl AsRef < str > ) -> Self { let input_key_material = key_string . as_ref ( ) ; // HKDF was chosen because it is designed to concentrate the entropy in a variable-length // input key and produce a higher quality but reduced-length output key with a // well-specified and reproducible algorithm. // // Granted, the input key is usually meant to be pseudorandom and not human readable, // but we're not trying to produce an unguessable value by any means; just one that's as // unlikely to already be in use as possible, but still deterministic. // // SHA-256 was chosen as the hash function because it's already used in the Postgres driver, // which should save on codegen and optimization. // We don't supply a salt as that is intended to be random, but we want a deterministic key. let hkdf = Hkdf :: < Sha256 > :: new ( None , input_key_material . as_bytes ( ) ) ; let mut output_key_material = [ 0u8 ; 8 ] ; // The first string is the "info" string of the HKDF which is intended to tie the output // exclusively to SQLx. This should avoid collisions with implementations using a similar // strategy. If you _want_ this to match some other implementation then you should get // the calculated integer key from it and use that directly. // // Do *not* change this string as it will affect the output! hkdf . expand ( b" " , & mut output_key_material , ) // `Hkdf::expand()` only returns an error if you ask for more than 255 times the digest size. // This is specified by RFC 5869 but not elaborated upon: // https://datatracker.ietf.org/doc/html/rfc5869#section-2.3 // Since we're only asking for 8 bytes, this error shouldn't be returned. . expect ( " " ) ; // For ease of use, this method assumes the user doesn't care which keyspace is used. // // It doesn't seem likely that someone would care about using the `(int, int)` keyspace // specifically unless they already had keys to use, in which case they wouldn't // care about this method. That's why we also provide `with_key()`. // // The choice of `from_le_bytes()` is mostly due to x86 being the most popular // architecture for server software, so it should be a no-op there. let key = PgAdvisoryLockKey :: BigInt ( i64 :: from_le_bytes ( output_key_material ) ) ; log :: trace ! ( " " key input_key_material ) ; Self :: with_key ( key ) }
Construct a `PgAdvisoryLock` using the given string as a key.
Construct a ` PgAdvisoryLock ` using the given string as a key .
key_string
impl AsRef<str>
example
None
extern crate sqlx_core as sqlx;
use sqlx::postgres::{PgAdvisoryLock, PgAdvisoryLockKey}.

let lock = PgAdvisoryLock::new("my first Postgres advisory lock!");
Negative values are fine because of how Postgres treats advisory lock keys.
See the documentation for the `pg_locks` system view for details.
use sqlx :: postgres :: { PgAdvisoryLock PgAdvisoryLockKey } . let lock = PgAdvisoryLock :: new ( " my first Postgres advisory lock! " ) ; Negative values are fine because of how Postgres treats advisory lock keys . See the documentation for the ` pg_locks ` system view for details .