#[repr(C)]pub struct SourceLocation {
pub line: u32,
pub column: u32,
}
Expand description
Source code location information
Stores the line and column number where a directive or clause appears in the original source file. This is useful for:
- Error reporting: “Error at line 42, column 5”
- IDE integration: Jump to source location
- Debugging: Know where IR came from
§Learning: The Copy
Trait
This struct implements Copy
, meaning it can be duplicated by simple
bitwise copy (like memcpy
in C). This is efficient for small types.
Types that implement Copy
must also implement Clone
. The difference:
Copy
: Implicit duplication (assignment creates a copy)Clone
: Explicit duplication (call.clone()
method)
§Learning: repr(C)
The #[repr(C)]
attribute tells Rust to lay out this struct in memory
exactly like C would. This is critical for FFI (Foreign Function Interface).
Without repr(C)
, Rust might reorder fields for optimization.
With repr(C)
, fields appear in declaration order.
§Example
use roup::ir::SourceLocation;
let loc = SourceLocation { line: 42, column: 5 };
let copy = loc; // Implicitly copied due to Copy trait
assert_eq!(loc.line, 42);
assert_eq!(copy.line, 42); // Original still valid
Fields§
§line: u32
Line number (1-indexed, as in editors)
column: u32
Column number (1-indexed, as in editors)
Implementations§
Trait Implementations§
Source§impl Clone for SourceLocation
impl Clone for SourceLocation
Source§fn clone(&self) -> SourceLocation
fn clone(&self) -> SourceLocation
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for SourceLocation
impl Debug for SourceLocation
Source§impl Default for SourceLocation
impl Default for SourceLocation
Source§impl Display for SourceLocation
impl Display for SourceLocation
Source§impl Hash for SourceLocation
impl Hash for SourceLocation
Source§impl PartialEq for SourceLocation
impl PartialEq for SourceLocation
impl Copy for SourceLocation
impl Eq for SourceLocation
impl StructuralPartialEq for SourceLocation
Auto Trait Implementations§
impl Freeze for SourceLocation
impl RefUnwindSafe for SourceLocation
impl Send for SourceLocation
impl Sync for SourceLocation
impl Unpin for SourceLocation
impl UnwindSafe for SourceLocation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more