piet_common/
lib.rs

1// Copyright 2019 the Piet Authors
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4//! A piet backend appropriate for the current platform.
5//!
6//! This crate reexports the [piet crate][piet], alongside an appropriate backend
7//! for the given platform. It also exposes [kurbo], which defines shape and
8//! curve types useful in drawing, and [image] for image manipulation.
9//!
10//! The intention of this crate is to provide a single dependency that handles
11//! the common piet use-case. If you have more complicated needs (such as
12//! supporting multiple backends simultaneously) you should use crates such as
13//! [piet] and [piet-cairo] directly.
14//!
15//! The associated types for brushes, text, and images are exported as type
16//! definitions (resolving to concrete types within the backend), so they can
17//! be used directly. The text-related types are prefixed with "Piet" to avoid
18//! conflict with the text traits that would otherwise have the same name.
19//!
20//! Also note that all public types for the specific backend are re-exported,
21//! but have their docs hidden here. These types can be useful for platform
22//! integration, and also potentially to access extensions specific to the
23//! backend. The types documented below can be used portable across all
24//! backends.
25//!
26//! [piet]: https://crates.io/crates/piet
27//! [kurbo]: https://crates.io/crates/kurbo
28//! [image]: https://crates.io/crates/image
29//! [piet-cairo]: https://crates.io/crates/piet-cairo
30
31#![cfg_attr(docsrs, feature(doc_auto_cfg))]
32#![deny(clippy::trivially_copy_pass_by_ref)]
33
34pub use piet::*;
35
36cfg_if::cfg_if! {
37     if #[cfg(target_arch = "wasm32")] {
38        #[path = "web_back.rs"]
39        mod backend;
40    } else if #[cfg(any(target_os = "linux", target_os = "openbsd", target_os = "freebsd", target_os = "netbsd"))] {
41        #[path = "cairo_back.rs"]
42        mod backend;
43    } else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
44        #[path = "cg_back.rs"]
45        mod backend;
46    } else if #[cfg(target_os = "windows")] {
47        #[path = "direct2d_back.rs"]
48        mod backend;
49    } else {
50        compile_error!("could not select an appropriate backend");
51    }
52}
53
54pub use backend::*;
55
56#[cfg(test)]
57mod test {
58    use super::*;
59
60    use static_assertions as sa;
61
62    // Make sure all the common types exist and don't get accidentally removed
63    #[allow(dead_code)]
64    struct Types<'a> {
65        piet: Piet<'a>,
66        brush: Brush,
67        piet_text: PietText,
68        piet_text_layout: PietTextLayout,
69        piet_text_layout_builder: PietTextLayoutBuilder,
70        image: PietImage,
71    }
72
73    sa::assert_impl_all!(Device: Send);
74    sa::assert_not_impl_any!(Device: Sync);
75}