Skip to content

Conversation

tomkris
Copy link

@tomkris tomkris commented Mar 16, 2025

Currently the only way to construct Aligned value is using aligned::Aligned function which returns instance of Aligned struct. This does not work well with type aliases. For example, consider this type alias:

/// Aligns value at cache line boundary (assuming 64 byte cache line size)
type CacheLineAligned<T> = Aligned<A64, T>;

User still has to use aligned::Aligned function to create value which breaks abstraction provided by type alias:

let cache_aligned_value: CacheLineAligned<u32> = aligned::Aligned(42);

In this commit I am implementing a conventional new constructor for struct Aligned which works with type aliases:

let cache_aligned_value = CacheLineAligned::new(42_u32);

Currently the only way to construct Aligned value is using `aligned::Aligned`
function which returns instance of `Aligned` struct. This does not work well
with type aliases. For example, consider this type alias:

```
/// Aligns value at cache line boundary (assuming 64 byte cache line size)
type CacheLineAligned<T> = Aligned<A64, T>;
```

User still has to use `aligned::Aligned` function to create value which breaks
abstraction provided by type alias:

```
let cache_aligned_value: CacheLineAligned<u32> = aligned::Aligned(42);
```

In this commit I am implementing a conventional `new` constructor for `struct Aligned`
which works with type aliases:

```
let cache_aligned_value = CacheLineAligned::new(42_u32);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant