coding style – Is this enum/trait a good way to implement polymorphic design in Rust?

this is my first post on here, and I’m wondering about a good rust implementation with traits on enum types. I want to know if using an enum w/ a trait as a generator of different code is viable like the one below? Also a couple of things I’m curious about is if there is an overhead with the match statement? Would implementing separate structs be faster?

struct GeneralCell {
    repr: char,
    position: Position,
    cell_type: Cell,
}

trait InitializeCells {
    fn new(&self, position: Position) -> GeneralCell;
}

pub enum Cell {
    Hall,
    Filled,
    Empty,
}

impl InitializeCells for Cell {
    fn new(&self, position: Position) -> GeneralCell {
        match self {
            Cell::Hall => GeneralCell {
                repr: 'H',
                position,
                cell_type: Cell::Hall,
            },
            Cell::Empty => GeneralCell {
                repr: 'E',
                position,
                cell_type: Cell::Empty,
            },
            Cell::Filled => GeneralCell {
                repr: 'F',
                position,
                cell_type: Cell::Filled,
            },
        }
    }
}

coding style – Dealing with unwanted usages of a function

I am writing a function that I would not like to get called given a certain context and am wondering how best to convey that to possible users of the function. Assume, for exemplification, I am writing a function process_payment that must not get called in an environment that demands certain security standards on the payments being done.
Some possible options of dealing with this I have thought of:

  1. Having a ...warning docstring comment ( or just a verbose comment in another programming language)
def process_payment(Payment payment):
"""
.. warning: DO NOT USE if we are in SECURE PAYMENT environment. Use a pipeline that leads to 
process_payment_securely() insead
"""
   (...)
  1. Specifically checking if the conditions are met inside the process_payment function by calling in some global state to check the conditions.
def process_payment(Payment payment):
    if get_payment_state() == SECURE_PAYMENT:
        raise Exception(...)
  1. Having the execution conditions be some values inside of a Payment class/struct, such that one can easily check them at the call site.
def process_payment(Payment payment):
    if payment.is_secure:
        raise Exception(...)

Obvious drawbacks to 1) are that it allows a not-careful user to process payments insecurely. Obvious drawbacks to 2) are that if the state which we are deciding with is quite far away in the call hierarchy, one needs to either call in some global state or propagate (potentially) a lot of information and pass it as an argument. Option 3) looks good, but one could imagine it being quite cumbersome and (depending on the programming language) suboptimal to include such redundant information into every Payment class.

Are there any other approaches I am missing? What are some common ways to deal with this?

dnd 4e – Grappling strike fighter power with brawler style – attack roll bonus

I (the DM) have a player with a level 11 fighter (brawler style).
She uses the power “Grappling strike” (Martial Power 2 p7) with a bastard sword (+2), and we disagree on bonuses to attack roll.

The power states:

Hit: 1 (W) + Strength modifier damage, and you grab the target. The grab ends automatically at the end of your next turn.

And the brawler style (Martial Power 2 p6 with errata) states:

In addition, you gain a +2 enhancement bonus to the attack rolls of unarmed attacks and a +2 bonus to the attack rolls of grab attacks and attacks to move a creature you’re grabbing. These bonuses increase to +4 at 11th level and +6 at 21st level

She thinks the attack roll should have the brawler style bonus (+4 at level 11).
But I think that bonus should not be counted, as it is for grab attack only,
and grappling strike is an attack with just a grab effect/consequence.

I think the brawler style applies only to the grab action, describe in PHB 1, p290.

As English is not our native language, we may misunderstood this bonus.

A +4 bonus at level 11 seems a little overpowered for an at-will power, it can change:

1d20 + 17 (5 half level, 5 str, 3 proficiency, 2 alteration, 2 feat)

to:

1d20 + 21

A standard monster has 25 AC (DMG 1, p184): she will hit on 4+!

Can you please tell us which understanding is right ?

programming practices – Style of nesting folders

So I’m currently deliberating on how to oragnize my folders. The background is that I am working with GraphQL so there will be types that depend on other types, which internally will then call their respective APIs to get their properties.

Should I organize them into outer grouped folders first, which would provide much more readily understanding structure, although possibly be more difficult to find files:

.
├── stage-1/
│   ├── chicken
│   ├── cow
│   └── wheat
├── stage-2/
│   ├── flour - wheat
│   ├── milk - cow
│   └── egg - chicken
├── stage-3/
│   └── dough - flour, milk, chicken
└── stage-4/
    └── cake - depends on dough

Or should I just style them as typically?

.
├── chicken
├── cow
├── wheat
├── flour
├── milk
├── egg
├── dough
└── cake

unity – What game engine is best for platformer style games?

Thanks for contributing an answer to Game Development Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.

To learn more, see our tips on writing great answers.

Copying the theme style files and images to duplicate the website but with a difference

I have recently downloaded a nulled premium wordpress theme online and have been doing changes to see if I can build the website I want to with the theme. Now that I am satisfied with my result, I want to buy the theme license and give the authors’ credit and money that they deserve.

I just am not sure how to copy all the changes that I have made in the theme to the new website with the fresh theme installed. What should I do ? I want to use the same theme but I could not think of a way to copy all the changes. I changed some css settings and it is easy to copy paste that code, also I can copy the product and product categories ettc manually but I dont want to do them all again.

Thank you very much in advance.

magento2 – Show related products with list style on product page in Magento 2?

I was able to show the related products on the product page inside the ‘related product’ tab. However, it is in grid style. I’m wondering if there is a way to show them with “list style” ( like the category list page)?

enter image description here

this is the related product section of the catalog_product_view.xml

    <!--related product tab-->
    <block class="MagentoCatalogBlockProductProductListRelated" name="product.info.related" template="Magento_Catalog::product/view/info.phtml" group="detailed_info">
        <arguments>
            <argument name="type" xsi:type="string">related</argument>
            <argument translate="true" name="title" xsi:type="string">Related Products</argument>
            <argument name="sort_order" xsi:type="string">40</argument>
            <argument name="priority" xsi:type="string">6</argument>
        </arguments>            
    </block>

this is my current phtml template for related product

<?php
 echo $block->getChildHtml('catalog.product.related');
?>

I want it to show like this ( list style)
enter image description here

Does a dark default style limit potential? | Forum Promotion

On my upcoming forum I plan on adding both a dark and light style but I am contemplating on which should be the default style, which raises a very good question for all webmasters.

Although more websites are adopting a dark default design, traditionally it is thought that a light default design is more user friendly than the former. First impression is crucial to a site’s growth – it ultimately decides how many one-off visitors stick around, so the question I am posing is: are you limiting your site’s potential by using a dark default design?

plugins – Include Custom Style & Script into Custom Post Type Single Template

I’m creating a plugin to add a custom post type.
For every custom post type, I also create custom single template.
The custom single template is not using get_header(); or wp_head() functions, it is coded from scratch manually.
I’ve enqueued style like this:

<link rel="stylesheet" href="<?php echo esc_url( plugins_url( '/public/css/wp-myplugin-public.min.css', dirname(__FILE__) ) ); "/>

And when I submitted the plugin, the WordPress team encouraged me to use built-in WordPress function such as wp_enqueue_style()

Since I don’t use get_header() and wp_head, there’s no way it can be enqueued into the header of my single template.

I’ve tried several ways like this:

function wp_myplugin_enqueue_style() {
global $post;
if ($post->post_type == 'myplugin') {
       wp_enqueue_style( 'myplugin-public-css',  plugin_dir_url( __FILE__ ) . ' public/css/wp-myplugin-public.min.css ' );
}
}
add_action( 'wp_enqueue_scripts', ' wp_myplugin_enqueue_style' );

Including like this:

function wp_myplugin_enqueue_style() {
if ( get_post_type( get_the_ID() ) == 'myplugin' ) {
       wp_enqueue_style( 'myplugin-public-css',  plugin_dir_url( __FILE__ ) . ' public/css/wp-myplugin-public.min.css ' );
}
}
add_action( 'wp_enqueue_scripts', ' wp_myplugin_enqueue_style ' );

Also like this:

function wp_myplugin_enqueue_main_css() {
    if (is_page_template('wp-myplugin-base-template.php')){
    wp_enqueue_style( 'myplugin-public-css',  plugin_dir_url( __FILE__ ) . ' public/css/wp-myplugin-public.min.css ' );
    }
}
add_action( 'wp_enqueue_scripts', 'wp_myplugin_enqueue_main_css' );

The above codes didn’t work at all.

The of the single template looks like this:

<?php
** Custom Single Template for MyPlugin
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
    <head>
<?php if (in_array('wordpress-seo/wp-seo.php' || 'wordpress-seo-premium/wp-seo-premium.php', apply_filters( 'active_plugins', get_option('active_plugins' )))) :
    if ($meta_title = get_post_meta($post->ID, '_yoast_wpseo_title', true ));
    elseif ($meta_title = get_post_meta( get_the_ID(), myplugin_prefix( 'meta-title' ), true ));
    else $meta_title = get_option(sanitize_text_field('myplugin_meta_title'));
    if ($meta_description = get_post_meta($post->ID, '_yoast_wpseo_metadesc', true ));
    elseif ($meta_description = get_post_meta( get_the_ID(), myplugin_prefix( 'meta-description' ), true ));
    else $meta_description = get_option(sanitize_text_field('myplugin_meta_description'));
?>
<?php
if ($set_noindex = get_post_meta( get_the_ID(), myplugin_prefix( 'noindex' ), true ));
else $set_noindex = get_option(sanitize_text_field('wp_myplugin_noindex'));
if ($set_nofollow = get_post_meta( get_the_ID(), myplugin_prefix( 'nofollow' ), true ));
else $set_nofollow = get_option(sanitize_text_field('wp_myplugin_nofollow'));
?>
<?php
if ($set_noindex === "yes") {
$noindex = "noindex";
} else {
$noindex = "index";
}
if ($set_nofollow === "yes") {
$nofollow = "nofollow";
} else {
$nofollow = "follow";
}
?>
        <meta charset="<?php bloginfo( 'charset' ); ?>">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="profile" href="http://gmpg.org/xfn/11">
        <link rel="pingback" href="<?php echo esc_url( get_bloginfo( 'pingback_url' ) ); ?>">
        <link rel="icon" type="image/png" href="<?php echo esc_html(get_option('myplugin_upload_favicon')); ?>">
        <title><?php echo $meta_title; ?></title>
        <meta name="description" content="<?php echo $meta_description; ?>">
        <meta name="robots" content="<?php echo $noindex ?>, <?php echo $nofollow ?>" />
        <meta name="googlebot" content="<?php echo $noindex ?>, <?php echo $nofollow ?>, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
        <meta name="bingbot" content="<?php echo $noindex ?>, <?php echo $nofollow ?>, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
        <!-- WordPress team doesn't allow below method to enqueue style -->
        <link rel="stylesheet" href="<?php echo esc_url( plugins_url( '/css/wp-myplugin-public.min.css', dirname(__FILE__) ) ); ?>"/>
<?php get_header(); ?>
<?php endif; ?>
<?php $custom_css = get_option(sanitize_text_field('wp_myplugin_custom_css'));
if ($custom_css == '') {
    echo '';
} else {
    echo '<style type="text/css">'.$custom_css .'</style>';
  }
?>
    </head>

In order to include the wp-myplugin-public.min.css stylesheet, what is the best method I can use? I really need your help on this.

Thank you very much in advance!