Skip to main content

RenderingDetector

Struct RenderingDetector 

Source
pub struct RenderingDetector { /* private fields */ }
Expand description

Tells how a framework’s build is served from the build’s file names: the first option, in the order they were added, with one of its files for the framework among the inputs; otherwise static output, falling back to the only HTML file when there is exactly one.

PHP: Utopia\Detector\Detector\Rendering.

use utopia_detector::{RenderingDetector, Ssr, Static};

let mut detector = RenderingDetector::new("nextjs");
detector.add_option(Ssr::new()).add_option(Static::new());
detector.add_input("server/pages/index.html").add_input("server/pages/api/users.js");

let rendering = detector.detect();
assert_eq!(rendering.name(), "static");
assert_eq!(rendering.fallback_file(), Some("server/pages/index.html"));
use Utopia\Detector\Detection\Rendering\SSR;
use Utopia\Detector\Detection\Rendering\XStatic;
use Utopia\Detector\Detector\Rendering;

$detector = new Rendering('nextjs');
$detector->addOption(new SSR())->addOption(new XStatic());
$detector->addInput('server/pages/index.html')->addInput('server/pages/api/users.js');

$rendering = $detector->detect();
echo $rendering->getName(), "\n";         // static
echo $rendering->getFallbackFile(), "\n"; // server/pages/index.html

Implementations§

Source§

impl RenderingDetector

Source

pub fn new(framework: impl Into<String>) -> Self

A detector for the build of framework (a framework name, such as nextjs).

PHP: new Rendering($framework).

Source

pub fn add_option(&mut self, option: impl Rendering + 'static) -> &mut Self

Adds a rendering, tried after the others.

PHP: addOption($rendering).

Source

pub fn add_input(&mut self, file: impl Into<String>) -> &mut Self

Adds a file name of the build.

PHP: addInput($file).

Source

pub fn detect(&self) -> Rendered<'_>

The first option with a file for the framework among the inputs, or static output (with the only HTML file as the fallback, when there is exactly one).

PHP: detect().

Trait Implementations§

Source§

impl Debug for RenderingDetector

Source§

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

The framework, options’ names and inputs.

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.