Skip to content

Add Alignment::new constructor function #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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