Skip to content

Commit

Permalink
Put aliases to use and update possibly ambiguous UDFs to use names
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Sep 10, 2023
1 parent 33b020d commit a153e63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
26 changes: 2 additions & 24 deletions udf-uuid/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{HYPHENATED_UUID_LEN, HYPHENATED_UUID_LEN_U64, UUID_BYTES_LEN, UUID_B
#[derive(Debug, Default)]
struct UuidToBin(UuidBytes);

#[register]
#[register(name = "uuid_to_bin")]
impl BasicUdf for UuidToBin {
type Returns<'a> = Option<&'a [u8]>;

Expand Down Expand Up @@ -66,7 +66,7 @@ impl BasicUdf for UuidToBin {
#[derive(Debug)]
struct UuidFromBin([u8; HYPHENATED_UUID_LEN]);

#[register]
#[register(name = "uuid_from_bin", alias = "bin_to_uuid")]
impl BasicUdf for UuidFromBin {
type Returns<'a> = Option<&'a str>;

Expand Down Expand Up @@ -122,28 +122,6 @@ impl BasicUdf for UuidFromBin {
}
}

/// Alias to `uuid_from_bin`
#[derive(Debug)]
struct BinToUuid(UuidFromBin);

#[register]
impl BasicUdf for BinToUuid {
type Returns<'a> = Option<&'a str>;

fn init(cfg: &UdfCfg<Init>, args: &ArgList<Init>) -> Result<Self, String> {
Ok(Self(UuidFromBin::init(cfg, args)?))
}

fn process<'a>(
&'a mut self,
cfg: &UdfCfg<Process>,
args: &ArgList<Process>,
error: Option<NonZeroU8>,
) -> Result<Self::Returns<'a>, ProcessError> {
UuidFromBin::process(&mut self.0, cfg, args, error)
}
}

// Positions of components within a v1 UUID
const NODE: usize = 8;
const LOW_TIME: usize = 0;
Expand Down
16 changes: 8 additions & 8 deletions udf-uuid/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use crate::{validate_arg_count, HYPHENATED_UUID_LEN, HYPHENATED_UUID_LEN_U64};
#[derive(Debug)]
struct UuidGenerateV1 {
/// We save the mac address during the `init` call because that won't change.
/// Saves a few ms, maybe
/// Saves a few us, maybe
mac: [u8; 6],
res: [u8; HYPHENATED_UUID_LEN],
}

#[register]
#[register(name = "uuid_generate_v1")]
impl BasicUdf for UuidGenerateV1 {
type Returns<'a> = &'a [u8];

Expand Down Expand Up @@ -51,10 +51,10 @@ impl BasicUdf for UuidGenerateV1 {

/// V1 UUID with randomized MAC address
#[derive(Debug)]
struct UuidGenerateV1mc([u8; HYPHENATED_UUID_LEN]);
struct UuidGenerateV1RandomMac([u8; HYPHENATED_UUID_LEN]);

#[register]
impl BasicUdf for UuidGenerateV1mc {
#[register(name = "uuid_generate_v1mc")]
impl BasicUdf for UuidGenerateV1RandomMac {
type Returns<'a> = &'a [u8];

fn init(cfg: &UdfCfg<Init>, args: &ArgList<Init>) -> Result<Self, String> {
Expand Down Expand Up @@ -84,7 +84,7 @@ impl BasicUdf for UuidGenerateV1mc {
#[derive(Debug)]
struct UuidGenerateV4([u8; HYPHENATED_UUID_LEN]);

#[register]
#[register(name = "uuid_generate_v4")]
impl BasicUdf for UuidGenerateV4 {
type Returns<'a> = &'a [u8];

Expand All @@ -111,7 +111,7 @@ impl BasicUdf for UuidGenerateV4 {
#[derive(Debug)]
struct UuidGenerateV6([u8; HYPHENATED_UUID_LEN]);

#[register]
#[register(name = "uuid_generate_v6")]
impl BasicUdf for UuidGenerateV6 {
type Returns<'a> = &'a [u8];

Expand Down Expand Up @@ -160,7 +160,7 @@ impl BasicUdf for UuidGenerateV6 {
#[derive(Debug)]
struct UuidGenerateV7([u8; HYPHENATED_UUID_LEN]);

#[register]
#[register(name = "uuid_generate_v7")]
impl BasicUdf for UuidGenerateV7 {
type Returns<'a> = &'a [u8];

Expand Down
2 changes: 1 addition & 1 deletion udf-uuid/src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::validate_arg_count;
#[derive(Debug, PartialEq)]
struct UuidIsValid;

#[register]
#[register(name = "uuid_is_valid")]
impl BasicUdf for UuidIsValid {
type Returns<'a> = i64;

Expand Down

0 comments on commit a153e63

Please sign in to comment.