Skip to content

Commit

Permalink
Remove default generic argument. Improve docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
gz committed Apr 17, 2023
1 parent 2d13588 commit 53d1f7c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
17 changes: 10 additions & 7 deletions CHANGELOG.md
Expand Up @@ -5,21 +5,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [11.0.0] - XXXX-XX-XX
## [11.0.0] - 2023-04-17

### Breaking changes

- The `CpuId` type now takes a generic reader argument `CpuId<R: CpuIdReader>`:
the generic allows for more flexibility. This is a breaking change for users
which allows for more flexibility on how cpuid is queried and better support
for using the library on non-x86 targets. This is a breaking change for users
of `with_cpuid_fn` and potentially when specifying `CpuId` as a type argument
somewhere. To make existing code compile again, whenever a generic type
argument for CpuId is needed, you can use the `cpuid::NativeCpuIdReader` type
which provides the default behavior of reading the CPUID registers.
which provides the default behavior of execution the `cpuid` instruction.

Although we do specify a default generic type for CpuId to be
`cpuid::NativeCpuIdReader` there might be cases where you need to specify the
generic type of CpuId: e.g., `fn take_cpuid(cpuid: CpuId)` would become:
`fn take_cpuid(cpuid: CpuId<NativeCpuIdReader>)`
For example, in your code there might be cases where the compiler now asks you
to specify the generic type of CpuId: e.g., `fn take_cpuid(cpuid: CpuId)`
would become: `fn take_cpuid(cpuid: CpuId<NativeCpuIdReader>)`

See also [#140](https://github.com/gz/rust-cpuid/pull/140) and
[#138](https://github.com/gz/rust-cpuid/pull/138) for the original discussion.

- If you're using the `serialization` feature: It go revamped by fixing some
long-standing problems with it that made it difficult to use
Expand Down
2 changes: 2 additions & 0 deletions examples/cache.rs
@@ -1,4 +1,6 @@
//! Example that displays information about the caches.
//!
//! This example only compiles on x86 platforms.
extern crate raw_cpuid;
use raw_cpuid::{CacheType, CpuId};

Expand Down
2 changes: 2 additions & 0 deletions examples/cpu.rs
@@ -1,4 +1,6 @@
//! An example that displays the type/features/configuration of the CPU.
//!
//! This example only compiles on x86 platforms.
extern crate raw_cpuid;

fn main() {
Expand Down
2 changes: 2 additions & 0 deletions examples/topology.rs
Expand Up @@ -2,6 +2,8 @@
//!
//! Intel Topology is a pretty complicated subject (unfortunately):
//! https://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration/
//!
//! This example only compiles on x86 platforms.
extern crate core_affinity;
extern crate raw_cpuid;

Expand Down
4 changes: 3 additions & 1 deletion examples/tsc_frequency.rs
@@ -1,4 +1,6 @@
//! An example that determines the time stamp counter frequency (RDTSC, RDTSCP) .
//! An example that determines the time stamp counter frequency (RDTSC, RDTSCP).
//!
//! This example only compiles on x86 platforms.
extern crate raw_cpuid;

use std::time;
Expand Down
3 changes: 3 additions & 0 deletions src/bin/cpuid.rs
@@ -1,3 +1,6 @@
//! The cpuid binary accompanying the library.
//!
//! The cpuid binary only compiles/runs on x86 platforms.
use std::str::FromStr;

use clap::Parser;
Expand Down
14 changes: 1 addition & 13 deletions src/lib.rs
Expand Up @@ -220,19 +220,7 @@ impl Vendor {
///
/// Other structs can be accessed by going through this type.
#[derive(Clone, Copy)]
pub struct CpuId<
#[cfg(any(
all(target_arch = "x86", not(target_env = "sgx"), target_feature = "sse"),
all(target_arch = "x86_64", not(target_env = "sgx"))
))]
R: CpuIdReader=CpuIdReaderNative,

#[cfg(not(any(
all(target_arch = "x86", not(target_env = "sgx"), target_feature = "sse"),
all(target_arch = "x86_64", not(target_env = "sgx"))
)))]
R: CpuIdReader
> {
pub struct CpuId<R: CpuIdReader> {
/// A generic reader to abstract the cpuid interface.
read: R,
/// CPU vendor to differentiate cases where logic needs to differ in code .
Expand Down
2 changes: 2 additions & 0 deletions src/tests/mod.rs
@@ -1,4 +1,6 @@
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod i5_3337u;

mod i7_12700k;
mod ryzen_matisse;
mod xeon_gold_6252;

0 comments on commit 53d1f7c

Please sign in to comment.