Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 14, 2025

This PR implements a Word<const WORD_LENGTH: usize> wrapper struct around [u8; WORD_LENGTH] that provides base64 display functionality, as suggested in the original discussion.

Changes

New Word Struct

  • Added Word<const WORD_LENGTH: usize>([u8; WORD_LENGTH]) wrapper struct
  • Implements Display trait that shows base64 encoding of the wrapped byte array
  • Provides clean, readable output for debugging and logging

Conversion Traits

To ensure seamless integration with existing code, the following traits are implemented:

  • From<[u8; WORD_LENGTH]> and From<Word<WORD_LENGTH>> for easy conversion
  • AsRef<[u8; WORD_LENGTH]> and AsRef<[u8]> for reference access
  • Deref to [u8; WORD_LENGTH] for transparent usage

Usage Example

use cosmian_findex_structs::Word;

let word_bytes = [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]; // "Hello World!"
let word: Word<12> = Word::new(word_bytes);

println!("{}", word); // Outputs: SGVsbG8gV29ybGQh (base64)

// Seamless conversion back to byte array
let bytes: [u8; 12] = word.into();

Compatibility

The implementation maintains full backward compatibility:

  • Existing [u8; WORD_LENGTH] usage continues to work unchanged
  • Zero-cost abstractions through the Deref trait
  • Type safety preserved with compile-time size guarantees

Testing

Added comprehensive tests covering:

  • Base64 display functionality with known test vectors
  • All conversion trait implementations
  • Round-trip conversions
  • Integration with existing CUSTOM_WORD_LENGTH constant

Fixes #94.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Wrap [u8; WORD_LENGTH] under a struct Word([u8; WORD_LENGTH]) in order to impl Display for Word if you really want a base 64 display? Implement Word struct wrapper for [u8; WORD_LENGTH] with base64 Display Aug 14, 2025
@Copilot Copilot AI requested a review from Manuthor August 14, 2025 05:49
Copilot finished work on behalf of Manuthor August 14, 2025 05:49
@Manuthor Manuthor marked this pull request as ready for review August 16, 2025 21:58
Copilot AI and others added 2 commits August 16, 2025 23:59
Co-authored-by: Manuthor <32013169+Manuthor@users.noreply.github.com>
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.

Wrap [u8; WORD_LENGTH] under a struct Word([u8; WORD_LENGTH]) in order to impl Display for Word if you really want a base 64 display?

2 participants