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