1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 use std::fmt::{Display, Error, Formatter}; 16 17 /// Encapsulates a location in source code. 18 /// 19 /// This is intended to report the location of an assertion which failed to 20 /// stdout. 21 /// 22 /// **For internal use only. API stablility is not guaranteed!** 23 #[doc(hidden)] 24 pub struct SourceLocation { 25 file: &'static str, 26 line: u32, 27 column: u32, 28 } 29 30 impl SourceLocation { 31 /// Constructs a new [`SourceLocation`]. 32 /// 33 /// **For internal use only. API stablility is not guaranteed!** 34 #[doc(hidden)] new(file: &'static str, line: u32, column: u32) -> Self35 pub fn new(file: &'static str, line: u32, column: u32) -> Self { 36 Self { file, line, column } 37 } 38 } 39 40 impl Display for SourceLocation { fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>41 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { 42 write!(f, " at {}:{}:{}", self.file, self.line, self.column) 43 } 44 } 45