Skip to main content

squawk_ide/
file.rs

1// via https://github.com/rust-lang/rust-analyzer/blob/2efc80078029894eec0699f62ec8d5c1a56af763/crates/hir-expand/src/files.rs#L21C21-L21C21
2//
3// Permission is hereby granted, free of charge, to any
4// person obtaining a copy of this software and associated
5// documentation files (the "Software"), to deal in the
6// Software without restriction, including without
7// limitation the rights to use, copy, modify, merge,
8// publish, distribute, sublicense, and/or sell copies of
9// the Software, and to permit persons to whom the Software
10// is furnished to do so, subject to the following
11// conditions:
12//
13// The above copyright notice and this permission notice
14// shall be included in all copies or substantial portions
15// of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25// DEALINGS IN THE SOFTWARE.
26
27use crate::db::File;
28
29/// `InFile<T>` stores a value of `T` inside a particular file/syntax tree.
30///
31/// Typical usages are:
32///
33/// * `InFile<SyntaxNode>` -- syntax node in a file
34/// * `InFile<ast::FnDef>` -- ast node in a file
35/// * `InFile<TextSize>` -- offset in a file
36#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
37pub struct InFileWrapper<FileKind, T> {
38    pub file_id: FileKind,
39    pub value: T,
40}
41
42impl<FileKind, T> InFileWrapper<FileKind, T> {
43    pub fn new(file_id: FileKind, value: T) -> Self {
44        Self { file_id, value }
45    }
46}
47
48pub type InFile<T> = InFileWrapper<File, T>;