Skip to main content

Rule

Struct Rule 

Source
pub struct Rule {
    pub selectors: Vec<Selector>,
    pub declarations: Vec<Declaration>,
    pub layer: Option<usize>,
    pub media_query: Option<String>,
    pub container_query: Option<String>,
}

Fields§

§selectors: Vec<Selector>§declarations: Vec<Declaration>§layer: Option<usize>

@layer カスケードレイヤーの優先順位(None = レイヤー無し = 最優先)。 数値が大きいほど後から宣言されたレイヤーで、通常宣言(非 !important)では 後のレイヤーほど勝つ。!important との組み合わせ時の優先順位反転(仕様上の 細かい挙動)は非対応の簡略実装(!important は従来通りレイヤーを見ずに勝つ)。

§media_query: Option<String>

【2026-07-24追加】このルールを包む@media条件文字列(None = 無条件)。 以前は@mediaをCSS解析時(parse_css呼び出し時点)に一度だけ静的評価し、 マッチしなかったブロックを丸ごと除外していたため、その一度きりの解析時点の ウィンドウ幅と実際の表示時のウィンドウ幅がズレていると(起動直後のプレース ホルダーページ表示中など)、モバイルファーストCSS(既定非表示→min-width メディアクエリで表示)のナビゲーション等が永久に除外されたままになり、 ページが白紙同然になるバグの一因だった。ルール自体は常に保持し、カスケード (要素へのマッチング)時に毎回media_query_matchesで動的に判定することで、 ウィンドウ幅が変わってもレイアウトのたびに正しく再評価されるようにする。

§container_query: Option<String>

@container の条件式(media_query と同じく動的評価するため保持する)。

@media との違いは基準がビューポートではなく「問い合わせコンテナ」で あること。コンテナ寸法はレイアウトが決まるまで分からないので、 解析時に評価して落とすことはできない(@media を静的評価して ページが白紙化した過去の失敗と同じ轍を踏まないこと)。

形式は 名前|条件 または |条件(名前省略時)。

Trait Implementations§

Source§

impl Clone for Rule

Source§

fn clone(&self) -> Rule

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnsafeUnpin for Rule

§

impl UnwindSafe for Rule

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.