libreda_db/layout/io.rs
1// Copyright (c) 2020-2021 Thomas Kramer.
2// SPDX-FileCopyrightText: 2022 Thomas Kramer
3//
4// SPDX-License-Identifier: AGPL-3.0-or-later
5
6//! Input and output interface definitions for layouts.
7//!
8//! Implementations for the various layout formats are located in other crates.
9
10use crate::prelude::{LayoutBase, LayoutEdit};
11use std::io::{Read, Write};
12
13/// Trait for reading a layout from a byte stream.
14pub trait LayoutStreamReader {
15 /// Type of error that could happen while reading a layout.
16 type Error;
17 /// Read a layout from a byte stream and populate the layout data structure.
18 fn read_layout<R: Read, L: LayoutEdit<Coord = i32>>(
19 &self,
20 reader: &mut R,
21 layout: &mut L,
22 ) -> Result<(), Self::Error>;
23}
24
25/// Trait for writing a layout to a byte stream.
26pub trait LayoutStreamWriter {
27 /// Type of error that could happen while writing a layout.
28 type Error;
29 /// Write the layout data structure to a byte stream.
30 fn write_layout<W: Write, L: LayoutBase<Coord = i32>>(
31 &self,
32 writer: &mut W,
33 layout: &L,
34 ) -> Result<(), Self::Error>;
35}